Fix thinko coming from 000f3adf
pg_basebackup.c relies on the compression level to not be 0 to decide if compression should be used, but 000f3adf missed the fact that the default compression (Z_DEFAULT_COMPRESSION) is -1, which would be used if specifying --gzip without --compress. While on it, add some coverage for --gzip, as this is rather easy to miss. Reported-by: Christoph Berg Discussion: https://postgr.es/m/YdhRDMLjabtXOnhY@msg.df7cb.de
This commit is contained in:
parent
27b77ecf9f
commit
d0d62262d3
@ -524,7 +524,7 @@ LogStreamerMain(logstreamer_param *param)
|
|||||||
stream.do_sync);
|
stream.do_sync);
|
||||||
else
|
else
|
||||||
stream.walmethod = CreateWalTarMethod(param->xlog,
|
stream.walmethod = CreateWalTarMethod(param->xlog,
|
||||||
(compresslevel > 0) ?
|
(compresslevel != 0) ?
|
||||||
COMPRESSION_GZIP : COMPRESSION_NONE,
|
COMPRESSION_GZIP : COMPRESSION_NONE,
|
||||||
compresslevel,
|
compresslevel,
|
||||||
stream.do_sync);
|
stream.do_sync);
|
||||||
|
@ -10,7 +10,7 @@ use File::Path qw(rmtree);
|
|||||||
use Fcntl qw(:seek);
|
use Fcntl qw(:seek);
|
||||||
use PostgreSQL::Test::Cluster;
|
use PostgreSQL::Test::Cluster;
|
||||||
use PostgreSQL::Test::Utils;
|
use PostgreSQL::Test::Utils;
|
||||||
use Test::More tests => 113;
|
use Test::More tests => 115;
|
||||||
|
|
||||||
program_help_ok('pg_basebackup');
|
program_help_ok('pg_basebackup');
|
||||||
program_version_ok('pg_basebackup');
|
program_version_ok('pg_basebackup');
|
||||||
@ -630,7 +630,7 @@ note "Testing pg_basebackup with compression methods";
|
|||||||
# Check ZLIB compression if available.
|
# Check ZLIB compression if available.
|
||||||
SKIP:
|
SKIP:
|
||||||
{
|
{
|
||||||
skip "postgres was not built with ZLIB support", 3
|
skip "postgres was not built with ZLIB support", 5
|
||||||
if (!check_pg_config("#define HAVE_LIBZ 1"));
|
if (!check_pg_config("#define HAVE_LIBZ 1"));
|
||||||
|
|
||||||
$node->command_ok(
|
$node->command_ok(
|
||||||
@ -641,12 +641,23 @@ SKIP:
|
|||||||
'--format', 't'
|
'--format', 't'
|
||||||
],
|
],
|
||||||
'pg_basebackup with --compress');
|
'pg_basebackup with --compress');
|
||||||
|
$node->command_ok(
|
||||||
|
[
|
||||||
|
'pg_basebackup', '-D',
|
||||||
|
"$tempdir/backup_gzip2", '--gzip',
|
||||||
|
'--no-sync', '--format',
|
||||||
|
't'
|
||||||
|
],
|
||||||
|
'pg_basebackup with --gzip');
|
||||||
|
|
||||||
# Verify that the stored files are generated with their expected
|
# Verify that the stored files are generated with their expected
|
||||||
# names.
|
# names.
|
||||||
my @zlib_files = glob "$tempdir/backup_gzip/*.tar.gz";
|
my @zlib_files = glob "$tempdir/backup_gzip/*.tar.gz";
|
||||||
is(scalar(@zlib_files), 2,
|
is(scalar(@zlib_files), 2,
|
||||||
"two files created with gzip (base.tar.gz and pg_wal.tar.gz)");
|
"two files created with --compress (base.tar.gz and pg_wal.tar.gz)");
|
||||||
|
my @zlib_files2 = glob "$tempdir/backup_gzip2/*.tar.gz";
|
||||||
|
is(scalar(@zlib_files2), 2,
|
||||||
|
"two files created with --gzip (base.tar.gz and pg_wal.tar.gz)");
|
||||||
|
|
||||||
# Check the integrity of the files generated.
|
# Check the integrity of the files generated.
|
||||||
my $gzip = $ENV{GZIP_PROGRAM};
|
my $gzip = $ENV{GZIP_PROGRAM};
|
||||||
@ -655,7 +666,9 @@ SKIP:
|
|||||||
|| $gzip eq ''
|
|| $gzip eq ''
|
||||||
|| system_log($gzip, '--version') != 0);
|
|| system_log($gzip, '--version') != 0);
|
||||||
|
|
||||||
my $gzip_is_valid = system_log($gzip, '--test', @zlib_files);
|
my $gzip_is_valid =
|
||||||
|
system_log($gzip, '--test', @zlib_files, @zlib_files2);
|
||||||
is($gzip_is_valid, 0, "gzip verified the integrity of compressed data");
|
is($gzip_is_valid, 0, "gzip verified the integrity of compressed data");
|
||||||
rmtree("$tempdir/backup_gzip");
|
rmtree("$tempdir/backup_gzip");
|
||||||
|
rmtree("$tempdir/backup_gzip2");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user