diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl index 311391d7acd6..96fc0b4dc734 100644 --- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl +++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl @@ -221,6 +221,9 @@ sub get_dump_for_comparison $old_node_params{extra} = \@old_initdb_params; $oldnode->init(%old_node_params); +# Override log_statement set by Cluster.pm; logged statements are not as useful +# and consume CPU cycles unnecessarily. +$oldnode->append_conf('postgresql.conf', 'log_statement = none'); $oldnode->start; my $result; @@ -312,6 +315,8 @@ sub get_dump_for_comparison push @new_initdb_params, ('--locale-provider', 'libc'); $new_node_params{extra} = \@new_initdb_params; $newnode->init(%new_node_params); +# Override log_statement set by Cluster.pm; as explained in case of oldnode. +$newnode->append_conf('postgresql.conf', 'log_statement=none'); # Stabilize stats for comparison. $newnode->append_conf('postgresql.conf', 'autovacuum = off'); @@ -359,30 +364,34 @@ sub get_dump_for_comparison $oldnode->append_conf('postgresql.conf', 'autovacuum = off'); $oldnode->restart; +# Dump/restore Test. +# # Test that dump/restore of the regression database roundtrips cleanly. This # doesn't work well when the nodes are different versions, so skip it in that # case. Note that this isn't a pg_upgrade test, but it's convenient to do it # here because we've gone to the trouble of creating the regression database. # -# Do this while the old cluster is running before it is shut down by the -# upgrade test but after turning its autovacuum off for stable statistics. +# We execute this in two parts as follows: +# +# Part 1: Take dump from the old cluster while it is running before being shut +# down by the upgrade test but after turning its autovacuum off for stable +# statistics. If this part succeeds and is not skipped, it will leave behind +# dump to be restored and a dump file for comparison. +# +# Part 2: The dump is restored on the upgraded cluster once it is running. +# +# Though this separates the two parts spatially and temporally, it avoids +# creating a new cluster, thus saving time (and resources) in this already long +# running test. +my $regress_dump_file; +my $src_dump; SKIP: { - my $dstnode = PostgreSQL::Test::Cluster->new('dst_node'); - skip "different Postgres versions" - if ($oldnode->pg_version != $dstnode->pg_version); + if ($oldnode->pg_version != $newnode->pg_version); skip "source node not using default install" if (defined $oldnode->install_path); - # Setup destination database cluster with the same configuration as the - # source cluster to avoid any differences between dumps taken from both the - # clusters caused by differences in their configurations. - $dstnode->init(%old_node_params); - # Stabilize stats for comparison. - $dstnode->append_conf('postgresql.conf', 'autovacuum = off'); - $dstnode->start; - # Use --create in dump and restore commands so that the restored # database has the same configurable variable settings as the original # database so that the dumps taken from both databases taken do not @@ -390,27 +399,18 @@ sub get_dump_for_comparison # coverage for --create option. # # Use directory format so that we can use parallel dump/restore. - my $dump_file = "$tempdir/regression.dump"; + $regress_dump_file = "$tempdir/regression.dump"; $oldnode->command_ok( [ 'pg_dump', '-Fd', '-j2', '--no-sync', '-d' => $oldnode->connstr('regression'), - '--create', '-f' => $dump_file + '--create', '-f' => $regress_dump_file ], 'pg_dump on source instance'); - $dstnode->command_ok( - [ 'pg_restore', '--create', '-j2', '-d' => 'postgres', $dump_file ], - 'pg_restore to destination instance'); - - # Dump original and restored database for comparison. - my $src_dump = + # Dump original database for comparison. + $src_dump = get_dump_for_comparison($oldnode, 'regression', 'src_dump', 1); - my $dst_dump = - get_dump_for_comparison($dstnode, 'regression', 'dest_dump', 0); - - compare_files($src_dump, $dst_dump, - 'dump outputs from original and restored regression databases match'); } # Take a dump before performing the upgrade as a base comparison. Note @@ -629,4 +629,29 @@ sub get_dump_for_comparison compare_files($dump1_filtered, $dump2_filtered, 'old and new dumps match after pg_upgrade'); +# Execute Part 2 of Dump/restore Test. +SKIP: +{ + # Skip Part 2 if the dump to be restored and the dump file for comparison do + # not exist. Part 1 was not executed or did not succeed. + skip "no dump/restore test" + if not defined $regress_dump_file or not defined $src_dump; + + # Use --create option as explained in Part 1. Rename upgraded regression + # database so that pg_restore can succeed and the so that it's available for + # diagnosing problems if any. + $newnode->safe_psql('postgres', 'ALTER DATABASE regression RENAME TO + regression_upgraded'); + $newnode->command_ok( + [ 'pg_restore', '--create', '-j2', '-d' => 'postgres', $regress_dump_file ], + 'pg_restore to destination instance'); + + # Dump restored database for comparison. + my $dst_dump = + get_dump_for_comparison($newnode, 'regression', 'dest_dump', 0); + + compare_files($src_dump, $dst_dump, + 'dump outputs from original and restored regression databases match'); +} + done_testing();