aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-07-29 23:24:39 -0400
committerRobert Haas <rhaas@postgresql.org>2022-07-29 23:26:03 -0400
commitd92f2bc0dae35747387f006519a74d3058a6bcb8 (patch)
tree2e8235d03d917c0fa9dd3c1df0f6f17b03f04ad2
parent2eb3f167f991d4e37b101c56de4e449f63b7a637 (diff)
downloadpostgresql-d92f2bc0dae35747387f006519a74d3058a6bcb8.tar.gz
postgresql-d92f2bc0dae35747387f006519a74d3058a6bcb8.zip
Revise test case added in 43746996399541ecb5c7b188725a5f097c15ceae.
Instead of using command_ok() to run psql, use safe_psql(). wrasse isn't happy, and it be because of failure to pass -X to the psql invocation, which safe_psql() will do automatically. Since safe_psql() returns standard output instead of writing it to a file, this requires some changes to the incantation for running 'diff'. Test against the 'regression' database rather than 'postgres' so we test more than just one table. That also means we need to record the horizons later, after the test does "VACUUM FULL pg_largeobject". Add an ORDER BY clause to the horizon query for stability. Patch by me, reviewed by Tom Lane. Discussion: http://postgr.es/m/CA+TgmoaGBbpzgu3=du1f9zDUbkfycO0y=_uWrLFy=KKEqXWeLQ@mail.gmail.com
-rw-r--r--src/bin/pg_upgrade/t/002_pg_upgrade.pl62
1 files changed, 30 insertions, 32 deletions
diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index 09af8157d0d..4cbc75644c8 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -161,27 +161,6 @@ $newnode->command_ok(
],
'dump before running pg_upgrade');
-# Also record the relfrozenxid and relminmxid horizons.
-my $horizon_query = <<EOM;
-SELECT
- c.oid::regclass, c.relfrozenxid, c.relminmxid
-FROM
- pg_class c, pg_namespace n
-WHERE
- c.relnamespace = n.oid AND
- ((n.nspname !~ '^pg_temp_' AND n.nspname !~ '^pg_toast_temp_' AND
- n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade',
- 'pg_toast'))
- OR (n.nspname = 'pg_catalog' AND relname IN ('pg_largeobject')))
-EOM
-$horizon_query =~ s/\s+/ /g; # run it together on one line
-$newnode->command_ok(
- [
- 'psql', '-At', '-d', $oldnode->connstr('postgres'),
- '-o', "$tempdir/horizon1.txt", '-c', $horizon_query,
- ],
- 'horizons before running pg_upgrade');
-
# After dumping, update references to the old source tree's regress.so
# to point to the new tree.
if (defined($ENV{oldinstall}))
@@ -231,6 +210,23 @@ if (defined($ENV{oldinstall}))
$oldnode->safe_psql("regression", "VACUUM FULL pg_largeobject;");
+# Record the relfrozenxid and relminmxid horizons from the old server.
+my $horizon_query = <<EOM;
+SELECT
+ c.oid::regclass, c.relfrozenxid, c.relminmxid
+FROM
+ pg_class c, pg_namespace n
+WHERE
+ c.relnamespace = n.oid AND
+ ((n.nspname !~ '^pg_temp_' AND n.nspname !~ '^pg_toast_temp_' AND
+ n.nspname NOT IN ('pg_catalog', 'information_schema', 'binary_upgrade',
+ 'pg_toast'))
+ OR (n.nspname = 'pg_catalog' AND relname IN ('pg_largeobject')))
+ORDER BY c.oid::regclass::text
+EOM
+$horizon_query =~ s/\s+/ /g; # run it together on one line
+my $horizon1 = $oldnode->safe_psql('regression', $horizon_query);
+
# In a VPATH build, we'll be started in the source directory, but we want
# to run pg_upgrade in the build directory so that any files generated finish
# in it, like delete_old_cluster.{sh,bat}.
@@ -315,13 +311,8 @@ $newnode->command_ok(
],
'dump after running pg_upgrade');
-# And second record of horizons as well.
-$newnode->command_ok(
- [
- 'psql', '-At', '-d', $newnode->connstr('postgres'),
- '-o', "$tempdir/horizon2.txt", '-c', $horizon_query,
- ],
- 'horizons after running pg_upgrade');
+# And record the horizons from the upgraded cluster as well.
+my $horizon2 = $newnode->safe_psql('regression', $horizon_query);
# Compare the two dumps, there should be no differences.
my $compare_res = compare("$tempdir/dump1.sql", "$tempdir/dump2.sql");
@@ -341,14 +332,21 @@ if ($compare_res != 0)
}
# Compare the horizons, there should be no differences.
-$compare_res = compare("$tempdir/horizon1.txt", "$tempdir/horizon2.txt");
-is($compare_res, 0, 'old and new horizons match after pg_upgrade');
+my $horizons_ok = $horizon1 eq $horizon2;
+ok($horizons_ok, 'old and new horizons match after pg_upgrade');
# Provide more context if the horizons do not match.
-if ($compare_res != 0)
+if (! $horizons_ok)
{
+ # output is long, so use diff to compare
+ open my $fh, ">", "$tempdir/horizon1.txt" or die "could not open file: $!";
+ print $fh $horizon1;
+ close $fh;
+ open $fh, ">", "$tempdir/horizon2.txt" or die "could not open file: $!";
+ print $fh $horizon2;
my ($stdout, $stderr) =
- run_command([ 'diff', "$tempdir/horizon1.txt", "$tempdir/horizon2.txt" ]);
+ run_command([ 'diff', "$tempdir/horizon1.txt", "$tempdir/horizon2.txt" ]);
+ close $fh;
print "=== diff of $tempdir/horizon1.txt and $tempdir/horizon2.txt\n";
print "=== stdout ===\n";
print $stdout;