From fbd09a8f01792660a0ab0444cdd1b45445654136 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Tue, 25 Aug 2026 16:25:14 +0900 Subject: [PATCH v17 2/2] pg_upgrade: Add option to preserve commit timestamps Make commit timestamp transfer opt-in by adding the --preserve-commit-timestamps option. Without this option, retain the previous pg_upgrade behavior of discarding commit timestamp data. --- doc/src/sgml/ref/pgupgrade.sgml | 12 ++++++++++++ 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/010_transfer_commit_ts.pl | 2 +- 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml index e4e8c02e6d6..2e6b8289f6e 100644 --- a/doc/src/sgml/ref/pgupgrade.sgml +++ b/doc/src/sgml/ref/pgupgrade.sgml @@ -373,6 +373,18 @@ PostgreSQL documentation + + + + + preserve the commit timestamp during the upgrade. The upgrade would fail + if the old cluster enables + track_commit_timestamp + but new cluster does not. + + + + diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 27ba04cb837..64ba6c290d8 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -748,7 +748,8 @@ check_new_cluster(void) check_new_cluster_subscription_configuration(); - check_new_cluster_commit_ts(); + if (user_opts.do_copy_pg_commit_ts) + check_new_cluster_commit_ts(); } static void diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index 179eaf0d5e6..5a2224d993b 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}, + {"preserve-commit-timestamps", 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"), @@ -329,6 +333,7 @@ usage(void) printf(_(" --copy copy files to new cluster (default)\n")); printf(_(" --copy-file-range copy files to new cluster with copy_file_range\n")); printf(_(" --no-statistics do not import statistics from old cluster\n")); + printf(_(" --preserve-commit-timestamps preserve commit timestamps during the upgrade\n")); printf(_(" --set-char-signedness=OPTION set new cluster char signedness to \"signed\" or\n" " \"unsigned\"\n")); printf(_(" --swap move data directories to new cluster\n")); diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c index a3f9623f170..d6747766457 100644 --- a/src/bin/pg_upgrade/pg_upgrade.c +++ b/src/bin/pg_upgrade/pg_upgrade.c @@ -796,7 +796,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 813f54121aa..2ae59cfdd83 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/010_transfer_commit_ts.pl b/src/bin/pg_upgrade/t/010_transfer_commit_ts.pl index 17da0b75f72..f7dc4fa7225 100644 --- a/src/bin/pg_upgrade/t/010_transfer_commit_ts.pl +++ b/src/bin/pg_upgrade/t/010_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', '--preserve-commit-timestamps', '--old-datadir' => $old->data_dir, '--new-datadir' => $new->data_dir, '--old-bindir' => $old->config_data('--bindir'), -- 2.52.0