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 1pVmhU-0008Hy-VG for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Feb 2023 05:02:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pVmhT-00045e-Nq for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Feb 2023 05:02:23 +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 1pVmhT-00045S-Cd for pgsql-hackers@lists.postgresql.org; Sat, 25 Feb 2023 05:02:23 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pVmhO-0002PD-TK for pgsql-hackers@lists.postgresql.org; Sat, 25 Feb 2023 05:02:22 +0000 Received: by mail-il1-x12b.google.com with SMTP id b16so1023757iln.3 for ; Fri, 24 Feb 2023 21:02:18 -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=yYawBXpkZtzyQAakwKyl8U2QH9FQP0wMjGXC1gEyzkY=; b=dYV6qiSWdf42ldSfsr3+vD/lveAVImkqXS/I5PONgB9avPIFPl2oYzwxoR0XjH79N7 JalfN/Lya1rM2FNyke8ROP43ZDnzPVVPUw0KYwl674hJo7M+4T0BsFm0lTsRtcipxWwj iTO3IBWUgRaLEsEhd25OMK00fnBX60StMGwxpzM1ONPsGrYDt77kaHqDoRVZMA4V52a2 ptIPjz5ap7WsMR/K6zGSH2BDHlbRQOi7uu/NiTw+QuJ1eWGsTWwiHVYW9afy02ckJW46 tttaKOXktQXs1PAKXD8QSswTceDrca0ZAH1ql9TNnoyxx/Wrf65NgQCgioSMk6bZe0/2 0DUw== 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=yYawBXpkZtzyQAakwKyl8U2QH9FQP0wMjGXC1gEyzkY=; b=8CKnnMfeqF2TzTPUJNQ51JzQk/b9R3XT24FhUYFlWeDlGhb4aE1QegL3VgC7GPxqhy pfU6k76aFdLyRT9dwc0tDvYmVavuRkF83Jr79PKUJv/5ot4mLcxuA4xO9Cht8ZztmvjL bVHmBn/c06MReYbDu6CMTOfxHYLVOHFZU8+tsn3CD/gm3GzMZFobhrbO5XDanbrIvV1V s8Kez6DABOd/ue4QxxfzPHmIbAfhvwpuVSu/HOPX+xtSsFOeNPKLNtD1Vc/+TiqW1gkT Ri6nX8VCefGiON/T6QIg5PPGCM/WCwYZO2D5QClwAHWRaHISF5MHgROguwicj0948KPI DEBQ== X-Gm-Message-State: AO0yUKXlPZ/4OhogD2CwoopDbJ0QPZdetvaYdD2Q5N2OcOKtvGqkCPst 7X/1HmfeR1NSRCHFvWp7TkogIw== X-Google-Smtp-Source: AK7set80Inx5SnkTFihfnT5/zXhFpdyIAairFzZZoF/VKSpdhUYfBXoh9JXqihHR5OypTnpeF76RTA== X-Received: by 2002:a05:6e02:1e06:b0:315:9a7e:fb07 with SMTP id g6-20020a056e021e0600b003159a7efb07mr17792837ila.20.1677301336817; Fri, 24 Feb 2023 21:02:16 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id s16-20020a92cc10000000b00316fa493a88sm281517ilp.79.2023.02.24.21.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 21:02:16 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 07C3B800354; Fri, 24 Feb 2023 23:02:14 -0600 (CST) Date: Fri, 24 Feb 2023 23:02:14 -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: <20230225050214.GH1653@telsasoft.com> References: <6YZqN2HEE4yJxxxXWiMl4QWwKzLon0SdKETTGVkT9zjWnXMftGZjLKHHjGFuwC_5I6xL2s8nMXdLQGA4vEFveYXSHbfD9K9pDQvEJF2y99o=@pm.me> <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> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="p8BcnzLwh3ipgLRM" Content-Disposition: inline In-Reply-To: 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 --p8BcnzLwh3ipgLRM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. - I'm unclear about get_error_func(). That's called in three places from pg_backup_directory.c, after failures from write_func(), to supply an compression-specific error message to pg_fatal(). But it's not being used outside of directory format, nor for errors for other function pointers, or even for all errors in write_func(). Is there some reason why each compression method's write_func() shouldn't call pg_fatal() directly, with its compression-specific message ? - I still think supports_compression() should be renamed, or made into a static function in the necessary file. The main reason is that it's more clear what it indicates - whether compression is "implemented by pgdump" and not whether compression is "supported by this postgres build". It also seems possible that we'd want to add a function called something like supports_compression(), indicating whether the algorithm is supported by the current build. It'd be better if pgdump didn't subjugate that name. - Finally, the "Nothing to do in the default case" comment comes from Michael's commit 5e73a6048: + /* + * Custom and directory formats are compressed by default with gzip when + * available, not the others. + */ + if ((archiveFormat == archCustom || archiveFormat == archDirectory) && + !user_compression_defined) { #ifdef HAVE_LIBZ - if (archiveFormat == archCustom || archiveFormat == archDirectory) - compressLevel = Z_DEFAULT_COMPRESSION; - else + parse_compress_specification(PG_COMPRESSION_GZIP, NULL, + &compression_spec); +#else + /* Nothing to do in the default case */ #endif - compressLevel = 0; } As the comment says: for -Fc and -Fd, the compression is set to zlib, if enabled, and when not otherwise specified by the user. Before 5e73a6048, this set compressLevel=0 for -Fp and -Ft, *and* when zlib was unavailable. But I'm not sure why there's now an empty "#else". I also don't know what "the default case" refers to. Maybe the best thing here is to move the preprocessor #if, since it's no longer in the middle of a runtime conditional: #ifdef HAVE_LIBZ + if ((archiveFormat == archCustom || archiveFormat == archDirectory) && + !user_compression_defined) + parse_compress_specification(PG_COMPRESSION_GZIP, NULL, + &compression_spec); #endif ...but that elicits a warning about "variable set but not used"... -- Justin --p8BcnzLwh3ipgLRM Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-f-fixes-for-LZ4.patch" From e31901414a8509317297972d1033c2e08629d903 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_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 +++--- 7 files changed, 12 insertions(+), 14 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_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 --p8BcnzLwh3ipgLRM--