Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 44b6210

Browse files
ashutosh-bapatCommitfest Bot
authored and
Commitfest Bot
committed
Reduce time taken by 002_pg_upgrade test to run
This test is one of the longest running tests and 172259a makes it even longer by adding a test to dump/restore roundtrip of regression database. The test already creates two clusters for pg_upgrade test. When these clusters have same version and do not use custom installation, we run dump/restore test. The new upgraded cluster could be used as target of restore instead of creating a new cluster. But this separates the dump and restore phases of the test spatially and temporaly since the dump needs to be taken while the old cluster is running and it can be restored only after new upgraded cluster is running; in-between we run upgrade test. This separation affects readability of the test and hence wasn't attempted before. But since runtime of test seems to be more important, we take a hit on readability. We have added additional comments so as to link the two phases and improve readability. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reported-by: Andres Freund <andres@anarazel.de>
1 parent 7afca7e commit 44b6210

File tree

1 file changed

+46
-26
lines changed

1 file changed

+46
-26
lines changed

src/bin/pg_upgrade/t/002_pg_upgrade.pl

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -359,58 +359,53 @@ sub get_dump_for_comparison
359359
$oldnode->append_conf('postgresql.conf', 'autovacuum = off');
360360
$oldnode->restart;
361361

362+
# Dump/restore Test.
363+
#
362364
# Test that dump/restore of the regression database roundtrips cleanly. This
363365
# doesn't work well when the nodes are different versions, so skip it in that
364366
# case. Note that this isn't a pg_upgrade test, but it's convenient to do it
365367
# here because we've gone to the trouble of creating the regression database.
366368
#
367-
# Do this while the old cluster is running before it is shut down by the
368-
# upgrade test but after turning its autovacuum off for stable statistics.
369+
# We execute this in two parts as follows:
370+
#
371+
# Part 1: Take dump from the old cluster while it is running before being shut
372+
# down by the upgrade test but after turning its autovacuum off for stable
373+
# statistics. If this part succeeds and is not skipped, it will leave behind
374+
# dump to be restored and a dump file for comparison.
375+
#
376+
# Part 2: The dump is restored on the upgraded cluster once it is running.
377+
#
378+
# Though this separates the two parts spatially and temporally, it avoids
379+
# creating a new cluster, thus saving time (and resources) in this already long
380+
# running test.
381+
my $regress_dump_file;
382+
my $src_dump;
369383
SKIP:
370384
{
371-
my $dstnode = PostgreSQL::Test::Cluster->new('dst_node');
372-
373385
skip "different Postgres versions"
374-
if ($oldnode->pg_version != $dstnode->pg_version);
386+
if ($oldnode->pg_version != $newnode->pg_version);
375387
skip "source node not using default install"
376388
if (defined $oldnode->install_path);
377389

378-
# Setup destination database cluster with the same configuration as the
379-
# source cluster to avoid any differences between dumps taken from both the
380-
# clusters caused by differences in their configurations.
381-
$dstnode->init(%old_node_params);
382-
# Stabilize stats for comparison.
383-
$dstnode->append_conf('postgresql.conf', 'autovacuum = off');
384-
$dstnode->start;
385-
386390
# Use --create in dump and restore commands so that the restored
387391
# database has the same configurable variable settings as the original
388392
# database so that the dumps taken from both databases taken do not
389393
# differ because of locale changes. Additionally this provides test
390394
# coverage for --create option.
391395
#
392396
# Use directory format so that we can use parallel dump/restore.
393-
my $dump_file = "$tempdir/regression.dump";
397+
$regress_dump_file = "$tempdir/regression.dump";
394398
$oldnode->command_ok(
395399
[
396400
'pg_dump', '-Fd', '-j2', '--no-sync',
397401
'-d' => $oldnode->connstr('regression'),
398-
'--create', '-f' => $dump_file
402+
'--create', '-f' => $regress_dump_file
399403
],
400404
'pg_dump on source instance');
401405

402-
$dstnode->command_ok(
403-
[ 'pg_restore', '--create', '-j2', '-d' => 'postgres', $dump_file ],
404-
'pg_restore to destination instance');
405-
406-
# Dump original and restored database for comparison.
407-
my $src_dump =
406+
# Dump original database for comparison.
407+
$src_dump =
408408
get_dump_for_comparison($oldnode, 'regression', 'src_dump', 1);
409-
my $dst_dump =
410-
get_dump_for_comparison($dstnode, 'regression', 'dest_dump', 0);
411-
412-
compare_files($src_dump, $dst_dump,
413-
'dump outputs from original and restored regression databases match');
414409
}
415410

416411
# Take a dump before performing the upgrade as a base comparison. Note
@@ -629,4 +624,29 @@ sub get_dump_for_comparison
629624
compare_files($dump1_filtered, $dump2_filtered,
630625
'old and new dumps match after pg_upgrade');
631626

627+
# Execute Part 2 of Dump/restore Test.
628+
SKIP:
629+
{
630+
# Skip Part 2 if the dump to be restored and the dump file for comparison do
631+
# not exist. Part 1 was not executed or did not succeed.
632+
skip "no dump/restore test"
633+
if not defined $regress_dump_file or not defined $src_dump;
634+
635+
# Use --create option as explained in Part 1. Rename upgraded regression
636+
# database so that pg_restore can succeed and the so that it's available for
637+
# diagnosing problems if any.
638+
$newnode->safe_psql('postgres', 'ALTER DATABASE regression RENAME TO
639+
regression_upgraded');
640+
$newnode->command_ok(
641+
[ 'pg_restore', '--create', '-j2', '-d' => 'postgres', $regress_dump_file ],
642+
'pg_restore to destination instance');
643+
644+
# Dump restored database for comparison.
645+
my $dst_dump =
646+
get_dump_for_comparison($newnode, 'regression', 'dest_dump', 0);
647+
648+
compare_files($src_dump, $dst_dump,
649+
'dump outputs from original and restored regression databases match');
650+
}
651+
632652
done_testing();

0 commit comments

Comments
 (0)