Skip to content

Commit 8806e4e

Browse files
committed
002_pg_upgrade.pl: Move pg_dump test code for better stability
The alleged "statistics pg_dump bug" that prevented us from enabling stats dumping in commit 172259a wasn't a pg_dump bug after all: it was just a side effect of not running pg_dump at the right time (namely, before giving autovacuum some time to do its thing and then disabling it to stabilize things). Move the code around to fix this problem and enable statistics dumping. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Diagnosed-by: Jeff Davis <pgsql@j-davis.com> Discussion: https://postgr.es/m/5f3703fd7f27da62a8f3615218f937507f522347.camel@j-davis.com Discussion: https://postgr.es/m/CAExHW5sDm+aGb7A4EXK=X9rkrmSPDgc03EdADt=wWkdMO=XPSA@mail.gmail.com
1 parent abe5622 commit 8806e4e

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

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

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ sub get_dump_for_comparison
8383
open(my $dh, '>', $dump_adjusted)
8484
|| die "could not open $dump_adjusted for writing $!";
8585

86-
# Don't dump statistics, because there are still some bugs.
8786
$node->run_log(
8887
[
89-
'pg_dump', '--no-sync', '--no-statistics',
88+
'pg_dump', '--no-sync',
9089
'-d' => $node->connstr($db),
9190
'-f' => $dumpfile
9291
]);
@@ -301,64 +300,9 @@ sub get_dump_for_comparison
301300
is($rc, 0, 'regression tests pass');
302301
}
303302

304-
# Test that dump/restore of the regression database roundtrips cleanly. This
305-
# doesn't work well when the nodes are different versions, so skip it in that
306-
# case. Note that this isn't a pg_restore test, but it's convenient to do it
307-
# here because we've gone to the trouble of creating the regression database.
308-
#
309-
# Do this while the old cluster is running before it is shut down by the
310-
# upgrade test.
311-
SKIP:
312-
{
313-
my $dstnode = PostgreSQL::Test::Cluster->new('dst_node');
314-
315-
skip "different Postgres versions"
316-
if ($oldnode->pg_version != $dstnode->pg_version);
317-
skip "source node not using default install"
318-
if (defined $oldnode->install_path);
319-
320-
# Dump the original database for comparison later.
321-
my $src_dump =
322-
get_dump_for_comparison($oldnode, 'regression', 'src_dump', 1);
323-
324-
# Setup destination database cluster
325-
$dstnode->init(%old_node_params);
326-
# Stabilize stats for comparison.
327-
$dstnode->append_conf('postgresql.conf', 'autovacuum = off');
328-
$dstnode->start;
329-
330-
my $dump_file = "$tempdir/regression.dump";
331-
332-
# Use --create in dump and restore commands so that the restored
333-
# database has the same configurable variable settings as the original
334-
# database so that the dumps taken from both databases taken do not
335-
# differ because of locale changes. Additionally this provides test
336-
# coverage for --create option.
337-
#
338-
# Use directory format so that we can use parallel dump/restore.
339-
$oldnode->command_ok(
340-
[
341-
'pg_dump', '-Fd', '-j2', '--no-sync',
342-
'-d' => $oldnode->connstr('regression'),
343-
'--create', '-f' => $dump_file
344-
],
345-
'pg_dump on source instance');
346-
347-
$dstnode->command_ok(
348-
[ 'pg_restore', '--create', '-j2', '-d' => 'postgres', $dump_file ],
349-
'pg_restore to destination instance');
350-
351-
my $dst_dump =
352-
get_dump_for_comparison($dstnode, 'regression', 'dest_dump', 0);
353-
354-
compare_files($src_dump, $dst_dump,
355-
'dump outputs from original and restored regression databases match');
356-
}
357-
358303
# Initialize a new node for the upgrade.
359304
my $newnode = PostgreSQL::Test::Cluster->new('new_node');
360305

361-
362306
# The new cluster will be initialized with different locale settings,
363307
# but these settings will be overwritten with those of the original
364308
# cluster.
@@ -409,10 +353,66 @@ sub get_dump_for_comparison
409353
}
410354
}
411355

412-
# Stabilize stats before pg_dumpall.
356+
# Stabilize stats before pg_dump / pg_dumpall. Doing it after initializing
357+
# the new node gives enough time for autovacuum to update statistics on the
358+
# old node.
413359
$oldnode->append_conf('postgresql.conf', 'autovacuum = off');
414360
$oldnode->restart;
415361

362+
# Test that dump/restore of the regression database roundtrips cleanly. This
363+
# doesn't work well when the nodes are different versions, so skip it in that
364+
# case. Note that this isn't a pg_upgrade test, but it's convenient to do it
365+
# here because we've gone to the trouble of creating the regression database.
366+
#
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+
SKIP:
370+
{
371+
my $dstnode = PostgreSQL::Test::Cluster->new('dst_node');
372+
373+
skip "different Postgres versions"
374+
if ($oldnode->pg_version != $dstnode->pg_version);
375+
skip "source node not using default install"
376+
if (defined $oldnode->install_path);
377+
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+
386+
# Use --create in dump and restore commands so that the restored
387+
# database has the same configurable variable settings as the original
388+
# database so that the dumps taken from both databases taken do not
389+
# differ because of locale changes. Additionally this provides test
390+
# coverage for --create option.
391+
#
392+
# Use directory format so that we can use parallel dump/restore.
393+
my $dump_file = "$tempdir/regression.dump";
394+
$oldnode->command_ok(
395+
[
396+
'pg_dump', '-Fd', '-j2', '--no-sync',
397+
'-d' => $oldnode->connstr('regression'),
398+
'--create', '-f' => $dump_file
399+
],
400+
'pg_dump on source instance');
401+
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 =
408+
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');
414+
}
415+
416416
# Take a dump before performing the upgrade as a base comparison. Note
417417
# that we need to use pg_dumpall from the new node here.
418418
my @dump_command = (

0 commit comments

Comments
 (0)