mirror of https://github.com/postgres/postgres
Add a test to pg_upgrade's test suite that verifies that dump-restore-dump of regression database produces equivalent output to dumping it directly. This was already being tested by running pg_upgrade itself, but non-binary-upgrade mode was not being covered. The regression database has accrued, over time, a sufficient collection of interesting objects to ensure good coverage, but there hasn't been a concerted effort to be completely exhaustive, so it is likely still possible to have more. This'd belong more naturally in the pg_dump test suite, but we chose to put it in src/bin/pg_upgrade/t/002_pg_upgrade.pl because we need a run of the regression tests which is already done here, so this has less total test runtime impact. Also, experiments have shown that using parallel dump/restore is slightly faster, so we use --format=directory -j2. This test has already reported pg_dump bugs, as fixed inpull/208/headfd41ba93e4
,74563f6b90
,d611f8b158
,4694aedf63
. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://www.postgresql.org/message-id/CAExHW5uF5V=Cjecx3_Z=7xfh4rg2Wf61PT+hfquzjBqouRzQJQ@mail.gmail.com
parent
764d501d24
commit
172259afb5
@ -0,0 +1,157 @@ |
|||||||
|
# Copyright (c) 2024-2025, PostgreSQL Global Development Group |
||||||
|
|
||||||
|
=pod |
||||||
|
|
||||||
|
=head1 NAME |
||||||
|
|
||||||
|
PostgreSQL::Test::AdjustDump - helper module for dump/restore tests |
||||||
|
|
||||||
|
=head1 SYNOPSIS |
||||||
|
|
||||||
|
use PostgreSQL::Test::AdjustDump; |
||||||
|
|
||||||
|
# Adjust contents of dump output file so that dump output from original |
||||||
|
# regression database and that from the restored regression database match |
||||||
|
$dump = adjust_regress_dumpfile($dump, $adjust_child_columns); |
||||||
|
|
||||||
|
=head1 DESCRIPTION |
||||||
|
|
||||||
|
C<PostgreSQL::Test::AdjustDump> encapsulates various hacks needed to |
||||||
|
compare the results of dump/restore tests. |
||||||
|
|
||||||
|
=cut |
||||||
|
|
||||||
|
package PostgreSQL::Test::AdjustDump; |
||||||
|
|
||||||
|
use strict; |
||||||
|
use warnings FATAL => 'all'; |
||||||
|
|
||||||
|
use Exporter 'import'; |
||||||
|
use Test::More; |
||||||
|
|
||||||
|
our @EXPORT = qw( |
||||||
|
adjust_regress_dumpfile |
||||||
|
); |
||||||
|
|
||||||
|
=pod |
||||||
|
|
||||||
|
=head1 ROUTINES |
||||||
|
|
||||||
|
=over |
||||||
|
|
||||||
|
=item $dump = adjust_regress_dumpfile($dump, $adjust_child_columns) |
||||||
|
|
||||||
|
Edit a dump output file, taken from the source regression database, |
||||||
|
to remove the known differences to a dump taken after restoring the |
||||||
|
same database. |
||||||
|
|
||||||
|
Arguments: |
||||||
|
|
||||||
|
=over |
||||||
|
|
||||||
|
=item C<dump>: Contents of dump file |
||||||
|
|
||||||
|
=item C<adjust_child_columns>: 1 indicates that the given dump file requires |
||||||
|
adjusting columns in the child tables; usually when the dump is from original |
||||||
|
database. 0 indicates no such adjustment is needed; usually when the dump is |
||||||
|
from restored database. |
||||||
|
|
||||||
|
=back |
||||||
|
|
||||||
|
Returns the adjusted dump text. |
||||||
|
|
||||||
|
Adjustments Applied: |
||||||
|
|
||||||
|
=over |
||||||
|
|
||||||
|
=item Column reordering on child table creation |
||||||
|
|
||||||
|
This rearranges the column declarations in the C<CREATE TABLE... INHERITS> |
||||||
|
statements in the dump file from original database so that they match those |
||||||
|
from the restored database. |
||||||
|
|
||||||
|
Only executed if C<adjust_child_columns> is true. |
||||||
|
|
||||||
|
Context: some regression tests purposefully create child tables in such a way |
||||||
|
that the order of their inherited columns differ from column orders of their |
||||||
|
respective parents. In the restored database, however, the order of their |
||||||
|
inherited columns are same as that of their respective parents. Thus the column |
||||||
|
orders of these child tables in the original database and those in the restored |
||||||
|
database differ, causing difference in the dump outputs. See |
||||||
|
C<MergeAttributes()> and C<dumpTableSchema()> for details. |
||||||
|
|
||||||
|
=item Removal of problematic C<COPY> statements |
||||||
|
|
||||||
|
Remove COPY statements to abnormal children tables. |
||||||
|
|
||||||
|
Context: This difference is caused because of columns that are added to parent |
||||||
|
tables that already have children; because recreating the children tables puts |
||||||
|
the columns from the parent ahead of columns declared locally in children, |
||||||
|
these extra columns are in earlier position compared to the original database. |
||||||
|
Reordering columns on the entire C<COPY> data is impractical, so we just remove |
||||||
|
them. |
||||||
|
|
||||||
|
=item Newline adjustment |
||||||
|
|
||||||
|
Windows-style newlines are changed to Unix-style. Empty lines are trimmed. |
||||||
|
|
||||||
|
=back |
||||||
|
|
||||||
|
=cut |
||||||
|
|
||||||
|
sub adjust_regress_dumpfile |
||||||
|
{ |
||||||
|
my ($dump, $adjust_child_columns) = @_; |
||||||
|
|
||||||
|
# use Unix newlines |
||||||
|
$dump =~ s/\r\n/\n/g; |
||||||
|
|
||||||
|
# Adjust the CREATE TABLE ... INHERITS statements. |
||||||
|
if ($adjust_child_columns) |
||||||
|
{ |
||||||
|
$dump =~ s/(^CREATE\sTABLE\sgenerated_stored_tests\.gtestxx_4\s\() |
||||||
|
(\n\s+b\sinteger), |
||||||
|
(\n\s+a\sinteger\sNOT\sNULL)/$1$3,$2/mgx; |
||||||
|
|
||||||
|
$dump =~ s/(^CREATE\sTABLE\sgenerated_virtual_tests\.gtestxx_4\s\() |
||||||
|
(\n\s+b\sinteger), |
||||||
|
(\n\s+a\sinteger\sNOT\sNULL)/$1$3,$2/mgx; |
||||||
|
|
||||||
|
$dump =~ s/(^CREATE\sTABLE\spublic\.test_type_diff2_c1\s\() |
||||||
|
(\n\s+int_four\sbigint), |
||||||
|
(\n\s+int_eight\sbigint), |
||||||
|
(\n\s+int_two\ssmallint)/$1$4,$2,$3/mgx; |
||||||
|
|
||||||
|
$dump =~ s/(^CREATE\sTABLE\spublic\.test_type_diff2_c2\s\() |
||||||
|
(\n\s+int_eight\sbigint), |
||||||
|
(\n\s+int_two\ssmallint), |
||||||
|
(\n\s+int_four\sbigint)/$1$3,$4,$2/mgx; |
||||||
|
} |
||||||
|
|
||||||
|
# Remove COPY statements with differing column order |
||||||
|
for my $table ( |
||||||
|
'public\.b_star', 'public\.c_star', |
||||||
|
'public\.cc2', 'public\.d_star', |
||||||
|
'public\.e_star', 'public\.f_star', |
||||||
|
'public\.renamecolumnanother', 'public\.renamecolumnchild', |
||||||
|
'public\.test_type_diff2_c1', 'public\.test_type_diff2_c2', |
||||||
|
'public\.test_type_diff_c') |
||||||
|
{ |
||||||
|
# This multiline pattern matches the whole COPY, up to the |
||||||
|
# terminating "\." |
||||||
|
$dump =~ s/^COPY $table \(.+?^\\\.$//sm; |
||||||
|
} |
||||||
|
|
||||||
|
# Suppress blank lines, as some places in pg_dump emit more or fewer. |
||||||
|
$dump =~ s/\n\n+/\n/g; |
||||||
|
|
||||||
|
return $dump; |
||||||
|
} |
||||||
|
|
||||||
|
=pod |
||||||
|
|
||||||
|
=back |
||||||
|
|
||||||
|
=cut |
||||||
|
|
||||||
|
1; |
Loading…
Reference in new issue