From 9314852f137ce6f6dfb3d1d3e21713d9725102c0 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Tue, 25 Aug 2026 16:25:14 +0900 Subject: [PATCH v18 3/3] 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/logical-replication.sgml | 4 +++- doc/src/sgml/ref/pgupgrade.sgml | 12 ++++++++++++ src/bin/pg_upgrade/check.c | 7 ++++--- src/bin/pg_upgrade/option.c | 5 +++++ src/bin/pg_upgrade/pg_upgrade.h | 1 + src/bin/pg_upgrade/t/010_transfer_commit_ts.pl | 2 +- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 249e00f4440..2152ee02446 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -2872,7 +2872,9 @@ CONTEXT: processing remote data for replication origin "pg_16395" during "INSER FIXME: must be updated after the replication origin can be preserved. - Origin data is not preserved during the upgrade. As a result, even if + Origin data is not preserved during the upgrade. Also, commit timestamps + can be migrated only when + was specified. As a result, even if retain_dead_tuples is enabled, the upgraded subscriber may be unable to detect conflicts or log relevant commit timestamps and origins when applying changes from the diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml index 6c913bca8f2..4bd78d689b9 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 4e5f4525802..052ed25a5eb 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -765,10 +765,11 @@ determine_commit_ts_transfer(void) old_cluster.copy_commit_ts = false; /* - * Quick return if no commit timestamp information was available from - * pg_control. + * Quick return if 1) no commit timestamp information was available from + * pg_control or 2) not requested. */ - if (old_cluster.controldata.chkpnt_oldstCommitTsxid == 0 || + if (!user_opts.do_copy_pg_commit_ts || + old_cluster.controldata.chkpnt_oldstCommitTsxid == 0 || old_cluster.controldata.chkpnt_newstCommitTsxid == 0) return; 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.h b/src/bin/pg_upgrade/pg_upgrade.h index 0cf24c96c71..1cfb64d4d86 100644 --- a/src/bin/pg_upgrade/pg_upgrade.h +++ b/src/bin/pg_upgrade/pg_upgrade.h @@ -321,6 +321,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