|
36 | 36 | # to test pg_restore's ability to parse manually compressed files
|
37 | 37 | # that otherwise pg_dump does not compress on its own (e.g. *.toc).
|
38 | 38 | #
|
| 39 | +# glob_patterns is an optional array consisting of strings compilable |
| 40 | +# with glob() to check the files generated after a dump. |
| 41 | +# |
| 42 | +# command_like is an optional utility that can be used to compare |
| 43 | +# the output generated by a command on the contents of an existing |
| 44 | +# dump, like the TOC description of a pg_restore command. |
| 45 | +# |
39 | 46 | # restore_cmd is the pg_restore command to run, if any. Note
|
40 | 47 | # that this should generally be used when the pg_dump goes to
|
41 | 48 | # a non-text file and that the restore can then be used to
|
|
46 | 53 | # database and then pg_dump *that* database (or something along
|
47 | 54 | # those lines) to validate that part of the process.
|
48 | 55 |
|
| 56 | +my $supports_icu = ($ENV{with_icu} eq 'yes'); |
| 57 | +my $supports_lz4 = check_pg_config("#define USE_LZ4 1"); |
| 58 | +my $supports_gzip = check_pg_config("#define HAVE_LIBZ 1"); |
| 59 | + |
49 | 60 | my %pgdump_runs = (
|
50 | 61 | binary_upgrade => {
|
51 | 62 | dump_cmd => [
|
|
79 | 90 | "--file=$tempdir/compression_gzip_custom.sql",
|
80 | 91 | "$tempdir/compression_gzip_custom.dump",
|
81 | 92 | ],
|
| 93 | + command_like => { |
| 94 | + command => [ |
| 95 | + 'pg_restore', '-l', "$tempdir/compression_gzip_custom.dump", |
| 96 | + ], |
| 97 | + expected => qr/Compression: 1/, |
| 98 | + name => 'data content is gzip-compressed' |
| 99 | + }, |
82 | 100 | },
|
83 | 101 |
|
84 | 102 | # Do not use --no-sync to give test coverage for data sync.
|
|
96 | 114 | program => $ENV{'GZIP_PROGRAM'},
|
97 | 115 | args => [ '-f', "$tempdir/compression_gzip_dir/blobs.toc", ],
|
98 | 116 | },
|
| 117 | + # Verify that only data files where compressed |
| 118 | + glob_patterns => [ |
| 119 | + "$tempdir/compression_gzip_dir/toc.dat", |
| 120 | + "$tempdir/compression_gzip_dir/*.dat.gz", |
| 121 | + ], |
99 | 122 | restore_cmd => [
|
100 | 123 | 'pg_restore', '--jobs=2',
|
101 | 124 | "--file=$tempdir/compression_gzip_dir.sql",
|
|
198 | 221 | },
|
199 | 222 |
|
200 | 223 | # Do not use --no-sync to give test coverage for data sync.
|
| 224 | + # By default, the custom format compresses its data file |
| 225 | + # when the code is compiled with gzip support, and lets them |
| 226 | + # uncompressed when not compiled with it. |
201 | 227 | defaults_custom_format => {
|
202 | 228 | test_key => 'defaults',
|
203 |
| - compile_option => 'gzip', |
204 | 229 | dump_cmd => [
|
205 |
| - 'pg_dump', '-Fc', '-Z6', |
| 230 | + 'pg_dump', '-Fc', |
206 | 231 | "--file=$tempdir/defaults_custom_format.dump", 'postgres',
|
207 | 232 | ],
|
208 | 233 | restore_cmd => [
|
209 | 234 | 'pg_restore', '-Fc',
|
210 | 235 | "--file=$tempdir/defaults_custom_format.sql",
|
211 | 236 | "$tempdir/defaults_custom_format.dump",
|
212 | 237 | ],
|
| 238 | + command_like => { |
| 239 | + command => |
| 240 | + [ 'pg_restore', '-l', "$tempdir/defaults_custom_format.dump", ], |
| 241 | + expected => $supports_gzip ? |
| 242 | + qr/Compression: -1/ : |
| 243 | + qr/Compression: 0/, |
| 244 | + name => 'data content is gzip-compressed by default if available', |
| 245 | + }, |
213 | 246 | },
|
214 | 247 |
|
215 | 248 | # Do not use --no-sync to give test coverage for data sync.
|
| 249 | + # By default, the directory format compresses its data files |
| 250 | + # when the code is compiled with gzip support, and lets them |
| 251 | + # uncompressed when not compiled with it. |
216 | 252 | defaults_dir_format => {
|
217 | 253 | test_key => 'defaults',
|
218 | 254 | dump_cmd => [
|
|
224 | 260 | "--file=$tempdir/defaults_dir_format.sql",
|
225 | 261 | "$tempdir/defaults_dir_format",
|
226 | 262 | ],
|
| 263 | + command_like => { |
| 264 | + command => |
| 265 | + [ 'pg_restore', '-l', "$tempdir/defaults_dir_format", ], |
| 266 | + expected => $supports_gzip ? |
| 267 | + qr/Compression: -1/ : |
| 268 | + qr/Compression: 0/, |
| 269 | + name => 'data content is gzip-compressed by default', |
| 270 | + }, |
| 271 | + glob_patterns => [ |
| 272 | + "$tempdir/defaults_dir_format/toc.dat", |
| 273 | + "$tempdir/defaults_dir_format/blobs.toc", |
| 274 | + $supports_gzip ? |
| 275 | + "$tempdir/defaults_dir_format/*.dat.gz" : |
| 276 | + "$tempdir/defaults_dir_format/*.dat", |
| 277 | + ], |
227 | 278 | },
|
228 | 279 |
|
229 | 280 | # Do not use --no-sync to give test coverage for data sync.
|
|
3920 | 3971 | $collation_support = 1;
|
3921 | 3972 | }
|
3922 | 3973 |
|
3923 |
| -my $supports_icu = ($ENV{with_icu} eq 'yes'); |
3924 |
| -my $supports_lz4 = check_pg_config("#define USE_LZ4 1"); |
3925 |
| -my $supports_gzip = check_pg_config("#define HAVE_LIBZ 1"); |
3926 |
| -
|
3927 | 3974 | # ICU doesn't work with some encodings
|
3928 | 3975 | my $encoding = $node->safe_psql('postgres', 'show server_encoding');
|
3929 | 3976 | $supports_icu = 0 if $encoding eq 'SQL_ASCII';
|
|
4153 | 4200 | command_ok(\@full_compress_cmd, "$run: compression commands");
|
4154 | 4201 | }
|
4155 | 4202 |
|
| 4203 | + if ($pgdump_runs{$run}->{glob_patterns}) |
| 4204 | + { |
| 4205 | + my $glob_patterns = $pgdump_runs{$run}->{glob_patterns}; |
| 4206 | + foreach my $glob_pattern (@{$glob_patterns}) |
| 4207 | + { |
| 4208 | + my @glob_output = glob($glob_pattern); |
| 4209 | + is(scalar(@glob_output) > 0, 1, "$run: glob check for $glob_pattern"); |
| 4210 | + } |
| 4211 | + } |
| 4212 | +
|
| 4213 | + if ($pgdump_runs{$run}->{command_like}) |
| 4214 | + { |
| 4215 | + my $cmd_like = $pgdump_runs{$run}->{command_like}; |
| 4216 | + $node->command_like(\@{ $cmd_like->{command} }, |
| 4217 | + $cmd_like->{expected}, |
| 4218 | + "$run: " . $cmd_like->{name}) |
| 4219 | + } |
| 4220 | +
|
4156 | 4221 | if ($pgdump_runs{$run}->{restore_cmd})
|
4157 | 4222 | {
|
4158 | 4223 | $node->command_ok(\@{ $pgdump_runs{$run}->{restore_cmd} },
|
|
0 commit comments