Debian Codegraph @

src/bin/pg_verifybackup/t/009_extract.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # This test aims to verify that the client can decompress and extract
5 # a backup which was compressed by the server.
6
7 use strict;
8 use warnings FATAL => 'all';
9 use File::Path qw(rmtree);
10 use PostgreSQL::Test::Cluster;
11 use PostgreSQL::Test::Utils;
12 use Test::More;
13 my $primary = PostgreSQL::Test::Cluster->new('primary');
14 $primary->init(allows_streaming => 1);
15 $primary->start;
16
17 my @test_configuration = (
18 {
19 'compression_method' => 'none',
20 'backup_flags' => [],
21 'enabled' => 1
22 },
23 {
24 'compression_method' => 'gzip',
25 'backup_flags' => [ '--compress', 'server-gzip:5' ],
26 'enabled' => check_pg_config("#define HAVE_LIBZ 1")
27 },
28 {
29 'compression_method' => 'lz4',
30 'backup_flags' => [ '--compress', 'server-lz4:5' ],
31 'enabled' => check_pg_config("#define USE_LZ4 1")
32 },
33 {
34 'compression_method' => 'zstd',
35 'backup_flags' => [ '--compress', 'server-zstd:5' ],
36 'enabled' => check_pg_config("#define USE_ZSTD 1")
37 },
38 {
39 'compression_method' => 'parallel zstd',
40 'backup_flags' => [ '--compress', 'server-zstd:workers=3' ],
41 'enabled' => check_pg_config("#define USE_ZSTD 1"),
42 'possibly_unsupported' =>
43 qr/could not set compression worker count to 3: Unsupported parameter/
44 });
45
46 for my $tc (@test_configuration)
47 {
48 my $backup_path = $primary->backup_dir . '/' . 'extract_backup';
49 my $method = $tc->{'compression_method'};
50
51 SKIP:
52 {
53 skip "$method compression not supported by this build", 2
54 if !$tc->{'enabled'};
55
56 # A backup with a valid compression method should work.
57 my $backup_stdout = '';
58 my $backup_stderr = '';
59 my $backup_result = $primary->run_log(
60 [
61 'pg_basebackup',
62 '--pgdata' => $backup_path,
63 '--wal-method' => 'fetch',
64 '--no-sync',
65 '--checkpoint' => 'fast',
66 '--format' => 'plain',
67 @{ $tc->{'backup_flags'} },
68 ],
69 '>' => \$backup_stdout,
70 '2>' => \$backup_stderr);
71 if ($backup_stdout ne '')
72 {
73 print "# standard output was:\n$backup_stdout";
74 }
75 if ($backup_stderr ne '')
76 {
77 print "# standard error was:\n$backup_stderr";
78 }
79 if ( !$backup_result
80 && $tc->{'possibly_unsupported'}
81 && $backup_stderr =~ /$tc->{'possibly_unsupported'}/)
82 {
83 skip "compression with $method not supported by this build", 2;
84 }
85 else
86 {
87 ok($backup_result, "backup done, compression $method");
88 }
89
90 # Make sure that it verifies OK.
91 $primary->command_ok(
92 [ 'pg_verifybackup', '--exit-on-error', $backup_path ],
93 "backup verified, compression method \"$method\"");
94 }
95
96 # Remove backup immediately to save disk space.
97 rmtree($backup_path);
98 }
99
100 done_testing();