Re: pg_basebackup's --gzip switch misbehaves
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2022-09-22T00:31:48Z
Lists: pgsql-hackers
On Tue, Sep 13, 2022 at 04:13:20PM +0900, Michael Paquier wrote:
> diff --git a/src/common/compression.c b/src/common/compression.c
> index da3c291c0f..ac26287d54 100644
> --- a/src/common/compression.c
> +++ b/src/common/compression.c
> @@ -249,36 +299,49 @@ expect_integer_value(char *keyword, char *value, pg_compress_specification *resu
> char *
> validate_compress_specification(pg_compress_specification *spec)
> {
> + int min_level = 1;
> + int max_level = 1;
> + int default_level = 0;
> +
> /* If it didn't even parse OK, it's definitely no good. */
> if (spec->parse_error != NULL)
> return spec->parse_error;
>
> /*
> - * If a compression level was specified, check that the algorithm expects
> - * a compression level and that the level is within the legal range for
> - * the algorithm.
> + * Check that the algorithm expects a compression level and it is
> + * is within the legal range for the algorithm.
> */
> - if ((spec->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
> + switch (spec->algorithm)
> {
> - int min_level = 1;
> - int max_level;
> -
> - if (spec->algorithm == PG_COMPRESSION_GZIP)
> + case PG_COMPRESSION_GZIP:
> max_level = 9;
> - else if (spec->algorithm == PG_COMPRESSION_LZ4)
> +#ifdef HAVE_LIBZ
> + default_level = Z_DEFAULT_COMPRESSION;
> +#endif
> + break;
> + case PG_COMPRESSION_LZ4:
> max_level = 12;
> - else if (spec->algorithm == PG_COMPRESSION_ZSTD)
> + default_level = 0; /* fast mode */
> + break;
> + case PG_COMPRESSION_ZSTD:
> max_level = 22;
I should've suggested to add:
> min_level = -7;
which has been supported since zstd 1.3.4 (and postgres requires 1.4.0).
I think at some point (maybe before releasing 1.3.4) the range was
increased to very large(small), negative levels. It's possible to query
the library about the lowest supported compression level, but then
there's a complication regarding the client-side library version vs the
server-side version. So it seems better to just use -7.
--
Justin
Commits
-
Make PG_TEST_NOCLEAN work for temporary directories in TAP tests
- 45cfa87e9c56 11.21 landed
- af36c13a7e92 12.16 landed
- b102e80ab822 13.12 landed
- c8987ea90cf2 14.9 landed
- 4b15868b698a 15.4 landed
- c24e9ef330ac 16.0 landed
- 8c12838001c2 17.0 landed
-
doc: document the TAP test environment variables
- c4421550fb57 16.0 landed
-
doc: update metacpan.org links to avoid redirects
- 5f80cd287c29 16.0 landed
-
Use min/max bounds defined by Zstd for compression level
- ade925e1693a 15.0 landed
- 18ac08f0b42d 16.0 landed
-
Fix incorrect value for "strategy" with deflateParams() in walmethods.c
- a9e99ff6b4ac 10.23 landed
- f01cc02259df 11.18 landed
- adb371c9cd95 12.13 landed
- a94576c377b7 13.9 landed
- 4b529f4697f3 14.6 landed
- b3c630cc9230 15.0 landed
- b447d6075db8 16.0 landed
-
Simplify handling of compression level with compression specifications
- 53332eacaff6 15.0 landed
- f352e2d08ac0 16.0 landed