kuroda.diffs

application/octet-stream

Filename: kuroda.diffs
Type: application/octet-stream
Part: 0
Message: RE: Patch for migration of the pg_commit_ts directory
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index c5e29485416..382da0485a7 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -782,14 +782,16 @@ check_new_cluster_pg_commit_ts(void)
 
 	prep_status("Checking for new cluster configuration for commit timestamp");
 	conn = connectToServer(&new_cluster, "template1");
-	res = executeQueryOrDie(conn, "SELECT setting "
-							"FROM pg_settings WHERE name = 'track_commit_timestamp'");
+	res = executeQueryOrDie(conn, "SELECT setting FROM pg_settings "
+								  "WHERE name = 'track_commit_timestamp'");
 	track_commit_timestamp_on = strcmp(PQgetvalue(res, 0, 0), "on") == 0;
 	PQclear(res);
 	PQfinish(conn);
 
-	if (old_cluster.controldata.chkpnt_newstCommitTsxid > 0 && !track_commit_timestamp_on)
+	if (!track_commit_timestamp_on &&
+		old_cluster.controldata.chkpnt_newstCommitTsxid > 0)
 		pg_fatal("\"track_commit_timestamp\" must be \"on\" but is set to \"off\"");
+
 	check_ok();
 }
 void
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index c46a4432fd2..70297f38dca 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -773,6 +773,7 @@ static void
 copy_xact_xlog_xid(void)
 {
 	bool		is_copy_commit_ts;
+	uint32		oldest_xid, newest_xid;
 
 	/*
 	 * Copy old commit logs to new data dir. pg_clog has been renamed to
@@ -786,11 +787,18 @@ copy_xact_xlog_xid(void)
 	/*
 	 * Copy old commit_timestamp data to new, if available.
 	 */
-	is_copy_commit_ts = old_cluster.controldata.chkpnt_oldstCommitTsxid > 0
-		&& old_cluster.controldata.chkpnt_newstCommitTsxid > 0;
+	is_copy_commit_ts =
+		(old_cluster.controldata.chkpnt_oldstCommitTsxid > 0 &&
+		 old_cluster.controldata.chkpnt_newstCommitTsxid > 0);
 
 	if (is_copy_commit_ts)
+	{
 		copy_subdir_files("pg_commit_ts", "pg_commit_ts");
+		oldest_xid = old_cluster.controldata.chkpnt_oldstCommitTsxid;
+		newest_xid = old_cluster.controldata.chkpnt_newstCommitTsxid;
+	}
+	else
+		oldest_xid = newest_xid = old_cluster.controldata.chkpnt_nxtxid;
 
 	prep_status("Setting oldest XID for new cluster");
 	exec_prog(UTILITY_LOG_FILE, NULL, true, true,
@@ -816,8 +824,8 @@ copy_xact_xlog_xid(void)
 	exec_prog(UTILITY_LOG_FILE, NULL, true, true,
 			  "\"%s/pg_resetwal\" -f -c %u,%u \"%s\"",
 			  new_cluster.bindir,
-			  is_copy_commit_ts ? old_cluster.controldata.chkpnt_oldstCommitTsxid : old_cluster.controldata.chkpnt_nxtxid,
-			  is_copy_commit_ts ? old_cluster.controldata.chkpnt_newstCommitTsxid : old_cluster.controldata.chkpnt_nxtxid,
+			  oldest_xid,
+			  newest_xid,
 			  new_cluster.pgdata);
 	check_ok();
 
diff --git a/src/bin/pg_upgrade/t/007_transfer_commit_ts.pl b/src/bin/pg_upgrade/t/007_transfer_commit_ts.pl
index 1b75bf17e8c..c67463ab961 100644
--- a/src/bin/pg_upgrade/t/007_transfer_commit_ts.pl
+++ b/src/bin/pg_upgrade/t/007_transfer_commit_ts.pl
@@ -17,58 +17,50 @@ my $old = PostgreSQL::Test::Cluster->new('old');
 $old->init;
 $old->append_conf('postgresql.conf', 'track_commit_timestamp = on');
 $old->start;
-my $resold = $old->safe_psql('postgres', "
+my $resold = $old->safe_psql(
+	'postgres', qq{
 		create table a(a int);
-                select xid,timestamp from pg_last_committed_xact();
-	");
+		select xid,timestamp from pg_last_committed_xact();
+});
 
-my ($xid,$ts) = $resold =~ /\s*(\d+)\s*\|(.*)/;
+my ($xid, $ts) = $resold =~ /\s*(\d+)\s*\|(.*)/;
 $old->stop;
 
 # Initialize new cluster
 my $new = PostgreSQL::Test::Cluster->new('new');
 $new->init;
+
+# Setup a common pg_upgrade command to be used by all the test cases
+my @pg_upgrade_cmd = (
+	'pg_upgrade', '--no-sync',
+	'--old-datadir' => $old->data_dir,
+	'--new-datadir' => $new->data_dir,
+	'--old-bindir' => $old->config_data('--bindir'),
+	'--new-bindir' => $new->config_data('--bindir'),
+	'--socketdir' => $new->host,
+	'--old-port' => $old->port,
+	'--new-port' => $new->port,
+	$mode);
+
+# 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}.
+chdir ${PostgreSQL::Test::Utils::tmp_check};
+
 command_checks_all(
-	[
-		'pg_upgrade', '--no-sync',
-		'--old-datadir' => $old->data_dir,
-		'--new-datadir' => $new->data_dir,
-		'--old-bindir' => $old->config_data('--bindir'),
-		'--new-bindir' => $new->config_data('--bindir'),
-		'--socketdir' => $new->host,
-		'--old-port' => $old->port,
-		'--new-port' => $new->port,
-		$mode
-	],
-	1,
-	[qr{"track_commit_timestamp" must be "on" but is set to "off"}],
-	[],
+	[@pg_upgrade_cmd], 1,
+	[qr{"track_commit_timestamp" must be "on" but is set to "off"}], [],
 	'run of pg_upgrade for mismatch parameter track_commit_timestamp');
 
-
 $new->append_conf('postgresql.conf', 'track_commit_timestamp = on');
 
-command_checks_all(
-	[
-		'pg_upgrade', '--no-sync',
-		'--old-datadir' => $old->data_dir,
-		'--new-datadir' => $new->data_dir,
-		'--old-bindir' => $old->config_data('--bindir'),
-		'--new-bindir' => $new->config_data('--bindir'),
-		'--socketdir' => $new->host,
-		'--old-port' => $old->port,
-		'--new-port' => $new->port,
-		$mode
-	],
-	0,
-	[],
-	[],
-	'run of pg_upgrade ok');
+command_ok([@pg_upgrade_cmd], 'run of pg_upgrade ok');
 
 $new->start;
-my $resnew = $new->safe_psql('postgres', "
-                select $xid,pg_xact_commit_timestamp(${xid}::text::xid);
-	");
+my $resnew = $new->safe_psql(
+	'postgres', qq{
+	select $xid,pg_xact_commit_timestamp(${xid}::text::xid);
+});
 $new->stop;
 ok($resold eq $resnew, "timestamp transferred successfully");