From c8d9fdd98e1a8bd8b5db3c7900e984f367a01c57 Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Tue, 25 Aug 2026 16:25:14 +0900
Subject: [PATCH v15 2/3] Add --pg-commit-ts option

---
 src/bin/pg_upgrade/check.c                     | 3 ++-
 src/bin/pg_upgrade/option.c                    | 5 +++++
 src/bin/pg_upgrade/pg_upgrade.c                | 3 ++-
 src/bin/pg_upgrade/pg_upgrade.h                | 1 +
 src/bin/pg_upgrade/t/009_transfer_commit_ts.pl | 2 +-
 5 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index ba83737b0af..17ab7cf54af 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -710,7 +710,8 @@ check_new_cluster(void)
 
 	check_new_cluster_subscription_configuration();
 
-	check_new_cluster_pg_commit_ts();
+	if (user_opts.do_copy_pg_commit_ts)
+		check_new_cluster_pg_commit_ts();
 
 }
 
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index f01d2f92d95..5714e77ff4b 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -63,6 +63,7 @@ parseCommandLine(int argc, char *argv[])
 		{"no-statistics", no_argument, NULL, 5},
 		{"set-char-signedness", required_argument, NULL, 6},
 		{"swap", no_argument, NULL, 7},
+		{"pg-commit-ts", no_argument, NULL, 8},
 
 		{NULL, 0, NULL, 0}
 	};
@@ -233,6 +234,9 @@ parseCommandLine(int argc, char *argv[])
 			case 7:
 				user_opts.transfer_mode = TRANSFER_MODE_SWAP;
 				break;
+			case 8:
+				user_opts.do_copy_pg_commit_ts = true;
+				break;
 
 			default:
 				fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
@@ -325,6 +329,7 @@ usage(void)
 	printf(_("  -U, --username=NAME           cluster superuser (default \"%s\")\n"), os_info.user);
 	printf(_("  -v, --verbose                 enable verbose internal logging\n"));
 	printf(_("  -V, --version                 display version information, then exit\n"));
+	printf(_("  --pg-commit-ts                copy pg_commit_ts directory\n"));
 	printf(_("  --clone                       clone instead of copying files to new cluster\n"));
 	printf(_("  --copy                        copy files to new cluster (default)\n"));
 	printf(_("  --copy-file-range             copy files to new cluster with copy_file_range\n"));
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index 43aea348024..e27ce5a16aa 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -780,7 +780,8 @@ copy_xact_xlog_xid(void)
 	 */
 	is_copy_commit_ts =
 		(old_cluster.controldata.chkpnt_oldstCommitTsxid > 0 &&
-		 old_cluster.controldata.chkpnt_newstCommitTsxid > 0);
+		 old_cluster.controldata.chkpnt_newstCommitTsxid > 0 &&
+		 user_opts.do_copy_pg_commit_ts);
 
 	if (is_copy_commit_ts)
 	{
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 71f37ae27a6..89042063daa 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -319,6 +319,7 @@ typedef struct
 	bool		check;			/* check clusters only, don't change any data */
 	bool		live_check;		/* check clusters only, old server is running */
 	bool		do_sync;		/* flush changes to disk */
+	bool		do_copy_pg_commit_ts;	/* copy pg_commit_ts directory */
 	transferMode transfer_mode; /* copy files or link them? */
 	int			jobs;			/* number of processes/threads to use */
 	char	   *socketdir;		/* directory to use for Unix sockets */
diff --git a/src/bin/pg_upgrade/t/009_transfer_commit_ts.pl b/src/bin/pg_upgrade/t/009_transfer_commit_ts.pl
index 17da0b75f72..7479be57fd6 100644
--- a/src/bin/pg_upgrade/t/009_transfer_commit_ts.pl
+++ b/src/bin/pg_upgrade/t/009_transfer_commit_ts.pl
@@ -32,7 +32,7 @@ $new->init;
 
 # Setup a common pg_upgrade command to be used by all the test cases
 my @pg_upgrade_cmd = (
-	'pg_upgrade', '--no-sync',
+	'pg_upgrade', '--no-sync', '--pg-commit-ts',
 	'--old-datadir' => $old->data_dir,
 	'--new-datadir' => $new->data_dir,
 	'--old-bindir' => $old->config_data('--bindir'),
-- 
2.52.0

