Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVvEf-0000oG-7P for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Feb 2023 14:09:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pVvEd-0003Ub-Sh for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Feb 2023 14:09:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVvBY-00051C-6z for pgsql-hackers@lists.postgresql.org; Sat, 25 Feb 2023 14:06:00 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pVvBV-0007TF-O9 for pgsql-hackers@lists.postgresql.org; Sat, 25 Feb 2023 14:05:59 +0000 Received: by mail-il1-x132.google.com with SMTP id z5so1459927ilq.0 for ; Sat, 25 Feb 2023 06:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=7YmwchZ0UNxWCew65vCTP6KSEncAinsqVPCGQybKZ6k=; b=5JFZXApjht+XLf2pEhUUDku2g7+ztO1VUXyp4VOOL2/jB5GkgIQmMxLokTalLGEcgV zVUWNPtaM8WVkQmec6b1uzAHnYCmMWk1+zjPDsrSTS8xf06Hb/8/el2u68o30DoaRSa8 bQx9sRtxAKnAnBgEu5478AEkDRk7iOHJRDY2S8rwS8uv5IrXAUZ4WoEhOzQInFLq+7G9 ll2g0GOv268aXTLdAUffH/kNJCL1N/NXPlDR1BvbutrTVbc7d8eXnu5GMn00zw4bBQFE I4a7J9smFiFM2T1Xv7KhmLhTgS4onD07Q2jh9dfESmBI9EVDCnSllmW2WCqYoskbMiH5 lYfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7YmwchZ0UNxWCew65vCTP6KSEncAinsqVPCGQybKZ6k=; b=pNcZwXFe3kJBTHdZxkS4dt9JlastQrlY5UOC+TIlgZLYt3fo/B1Q7v5QrhZHMN246r gGB1z3LClRkR4pHm1KwWN4EFdLbBoqnuIOddAWaqBlb95FM8DkxD6efOr+0bafDU1VHz d1yntV9OENV7Ci6MjZr5WKq1v7vQjQnCm7eztdwL2ayyo/gj1asSo/Xw7KVp5DAGQU4N 5Y2Kkj11tUBvFZpyG4PoEMH+d0D8GO3Qz0M0YLht6IMxlv4gFYCdl+j90+t+bGAUD3Mc hssBSYXzTjlo0eIsRgC80vCnzvFA1tcwLL81IkLO6qoUGW1s4UKD/aOWMuqwdYXkEQMs t/ow== X-Gm-Message-State: AO0yUKW6S/urbgzq/l0rHf+uauZ+ByD4Ojv0XOFojtbuXYh10iQxsyWB z9EawLg2uVmf6+GJT6fIs0svFw== X-Google-Smtp-Source: AK7set8df9Y3Tika5LMWIoAjVeh+iGjSinin5K53TCzyc/mKWr044V26x5z5P0fREVQ8pBfbpUSKww== X-Received: by 2002:a05:6e02:1947:b0:315:4b70:8370 with SMTP id x7-20020a056e02194700b003154b708370mr16291419ilu.9.1677333955523; Sat, 25 Feb 2023 06:05:55 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a5-20020a056638018500b003b1d7fbf810sm532389jaq.148.2023.02.25.06.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 06:05:54 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id D4603800570; Sat, 25 Feb 2023 08:05:53 -0600 (CST) Date: Sat, 25 Feb 2023 08:05:53 -0600 From: Justin Pryzby To: gkokolatos@pm.me Cc: Michael Paquier , Tomas Vondra , shiy.fnst@fujitsu.com, pgsql-hackers@lists.postgresql.org, Rachel Heaton Subject: Re: Add LZ4 compression in pg_dump Message-ID: <20230225140553.GI1653@telsasoft.com> References: <535565cd-b69f-c064-a845-15c0fc44db4a@enterprisedb.com> <22cb80ed-ec87-54c7-fd5b-cdcf79766bb1@enterprisedb.com> <8421f53d-c9f7-c02e-3278-9f9522a8e8f3@enterprisedb.com> <20230224015115.GS1653@telsasoft.com> <20230225050214.GH1653@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="lqtP4FxvQo6hb6bg" Content-Disposition: inline In-Reply-To: <20230225050214.GH1653@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --lqtP4FxvQo6hb6bg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Feb 24, 2023 at 11:02:14PM -0600, Justin Pryzby wrote: > I have some fixes (attached) and questions while polishing the patch for > zstd compression. The fixes are small and could be integrated with the > patch for zstd, but could be applied independently. One more - WriteDataToArchiveGzip() says: + if (cs->compression_spec.level == 0) + pg_fatal("requested to compress the archive yet no level was specified"); That was added at e9960732a. But if you specify gzip:0, the compression level is already enforced by validate_compress_specification(), before hitting gzip.c: | pg_dump: error: invalid compression specification: compression algorithm "gzip" expects a compression level between 1 and 9 (default at -1) 5e73a6048 intended that to work as before, and you *can* specify -Z0: The change is backward-compatible, hence specifying only an integer leads to no compression for a level of 0 and gzip compression when the level is greater than 0. $ time ./src/bin/pg_dump/pg_dump -h /tmp regression -t int8_tbl -Fp --compress 0 |file - /dev/stdin: ASCII text Right now, I think that pg_fatal in gzip.c is dead code - that was first added in the patch version sent on 21 Dec 2022. -- Justin --lqtP4FxvQo6hb6bg Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-f-fixes-for-LZ4.patch" From 07b446803ec89ccd0954583640f314fa7f77048f Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 24 Feb 2023 14:07:09 -0600 Subject: [PATCH] f!fixes for LZ4 --- doc/src/sgml/ref/pg_dump.sgml | 4 ++-- src/bin/pg_dump/compress_gzip.c | 7 ------- src/bin/pg_dump/compress_io.c | 2 +- src/bin/pg_dump/compress_io.h | 4 ++-- src/bin/pg_dump/compress_lz4.c | 4 ++-- src/bin/pg_dump/pg_backup_archiver.c | 4 ++-- src/bin/pg_dump/pg_dump.c | 2 -- src/bin/pg_dump/t/002_pg_dump.pl | 6 +++--- 8 files changed, 12 insertions(+), 21 deletions(-) diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 49d218905fb..6fbe49f7ede 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -331,7 +331,7 @@ PostgreSQL documentation can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip or - lz4tool. + lz4 tools. This format is compressed by default using gzip and also supports parallel dumps. @@ -655,7 +655,7 @@ PostgreSQL documentation Specify the compression method and/or the compression level to use. The compression method can be set to gzip or - lz4 or none for no compression. + lz4, or none for no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the diff --git a/src/bin/pg_dump/compress_gzip.c b/src/bin/pg_dump/compress_gzip.c index 0af65afeb4e..af68fd27a12 100644 --- a/src/bin/pg_dump/compress_gzip.c +++ b/src/bin/pg_dump/compress_gzip.c @@ -123,13 +123,6 @@ WriteDataToArchiveGzip(ArchiveHandle *AH, CompressorState *cs, gzipcs->outbuf = pg_malloc(ZLIB_OUT_SIZE + 1); gzipcs->outsize = ZLIB_OUT_SIZE; - /* - * A level of zero simply copies the input one block at the time. This - * is probably not what the user wanted when calling this interface. - */ - if (cs->compression_spec.level == 0) - pg_fatal("requested to compress the archive yet no level was specified"); - if (deflateInit(zp, cs->compression_spec.level) != Z_OK) pg_fatal("could not initialize compression library: %s", zp->msg); diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c index ce06f1eac9c..9239dbb2755 100644 --- a/src/bin/pg_dump/compress_io.c +++ b/src/bin/pg_dump/compress_io.c @@ -83,7 +83,7 @@ * used by the caller in an error message. */ char * -supports_compression(const pg_compress_specification compression_spec) +pgdump_supports_compression(const pg_compress_specification compression_spec) { const pg_compress_algorithm algorithm = compression_spec.algorithm; bool supported = false; diff --git a/src/bin/pg_dump/compress_io.h b/src/bin/pg_dump/compress_io.h index bbde2693915..46815fa2ebe 100644 --- a/src/bin/pg_dump/compress_io.h +++ b/src/bin/pg_dump/compress_io.h @@ -21,7 +21,7 @@ #define ZLIB_OUT_SIZE 4096 #define ZLIB_IN_SIZE 4096 -extern char *supports_compression(const pg_compress_specification compression_spec); +extern char *pgdump_supports_compression(const pg_compress_specification compression_spec); /* * Prototype for callback function used in writeData() @@ -172,7 +172,7 @@ struct CompressFileHandle extern CompressFileHandle *InitCompressFileHandle(const pg_compress_specification compression_spec); /* - * Initialize a compress file stream. Deffer the compression algorithm + * Initialize a compress file stream. Infer the compression algorithm * from 'path', either by examining its suffix or by appending the supported * suffixes in 'path'. */ diff --git a/src/bin/pg_dump/compress_lz4.c b/src/bin/pg_dump/compress_lz4.c index fe1014e6e77..63e794cdc68 100644 --- a/src/bin/pg_dump/compress_lz4.c +++ b/src/bin/pg_dump/compress_lz4.c @@ -161,8 +161,8 @@ typedef struct LZ4File } LZ4File; /* - * LZ4 equivalent to feof() or gzeof(). The end of file is reached if there - * is no decompressed output in the overflow buffer and the end of the file + * LZ4 equivalent to feof() or gzeof(). Return true iff there is no + * decompressed output in the overflow buffer and the end of the backing file * is reached. */ static int diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 61ebb8fe85d..2063d6f239d 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -388,7 +388,7 @@ RestoreArchive(Archive *AHX) { if (te->hadDumper && (te->reqs & REQ_DATA) != 0) { - char *errmsg = supports_compression(AH->compression_spec); + char *errmsg = pgdump_supports_compression(AH->compression_spec); if (errmsg) pg_fatal("cannot restore from compressed archive (%s)", errmsg); @@ -3745,7 +3745,7 @@ ReadHead(ArchiveHandle *AH) else AH->compression_spec.algorithm = PG_COMPRESSION_GZIP; - errmsg = supports_compression(AH->compression_spec); + errmsg = pgdump_supports_compression(AH->compression_spec); if (errmsg) { pg_log_warning("archive is compressed, but this installation does not support compression (%s) -- no data will be available", diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 24ba936332d..ce2242195f3 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -733,8 +733,6 @@ main(int argc, char **argv) #ifdef HAVE_LIBZ parse_compress_specification(PG_COMPRESSION_GZIP, NULL, &compression_spec); -#else - /* Nothing to do in the default case */ #endif } diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index 72b19ee6cde..ad7bc5c194b 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -4248,10 +4248,10 @@ foreach my $run (sort keys %pgdump_runs) my $test_key = $run; my $run_db = 'postgres'; - # Skip command-level tests for gzip if there is no support for it. + # Skip command-level tests for gzip/lz4 if they're not supported. if ($pgdump_runs{$run}->{compile_option} && - ($pgdump_runs{$run}->{compile_option} eq 'gzip' && !$supports_gzip) || - ($pgdump_runs{$run}->{compile_option} eq 'lz4' && !$supports_lz4)) + (($pgdump_runs{$run}->{compile_option} eq 'gzip' && !$supports_gzip) || + ($pgdump_runs{$run}->{compile_option} eq 'lz4' && !$supports_lz4))) { note "$run: skipped due to no $pgdump_runs{$run}->{compile_option} support"; next; -- 2.34.1 --lqtP4FxvQo6hb6bg--