From 90e9904fa77021c76feb2ac5b208796695e53856 Mon Sep 17 00:00:00 2001
From: Sergey Levin <ls7777@yandex.ru>
Date: Wed, 11 Mar 2026 22:24:54 +0500
Subject: [PATCH 2/2] [PATCH v11 2/2] pg_upgrade: transfer commit timestamps to
 the new  cluster

This commit preserves commit timestamps during an upgrade. The advantage of this
commit is not only to provide committed transaction information after the upgrade,
but also to allow detecting {UPDATE|DELETE}_ORIGIN_DIFFERS conflicts for tuples
that were modified before the upgrade.

Files in the pg_commit_ts directory are copied when track_commit_timestamp=on.
Also, pg_resetwal specifies the oldest and newest transaction IDs to the new
cluster.

If the old cluster enables tracking commit timestamps but the new cluster does
not, the pg_upgrade fails to avoid missing them.

Author: Sergey Levin <ls7777@yandex.ru>
Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Maxim Orlov <orlovmg.gmail.com>
---
 doc/src/sgml/logical-replication.sgml |  8 ++++----
 src/bin/pg_upgrade/pg_upgrade.c       | 12 +++++-------
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml
index bcb473c078b..0468ac36eef 100644
--- a/doc/src/sgml/logical-replication.sgml
+++ b/doc/src/sgml/logical-replication.sgml
@@ -2818,11 +2818,11 @@ CONTEXT:  processing remote data for replication origin "pg_16395" during "INSER
 
    <note>
     <para>
-     Commit timestamps and origin data are not preserved during the upgrade.
-     As a result, even if
+     Parameters for physical replication slots are not preserved during the
+     upgrade. As a result, even if
      <link linkend="sql-createsubscription-params-with-retain-dead-tuples"><literal>retain_dead_tuples</literal></link>
-     is enabled, the upgraded subscriber may be unable to detect conflicts or
-     log relevant commit timestamps and origins when applying changes from the
+     is enabled, the upgraded subscriber may be unable to detect
+     <literal>update_deleted</literal> conflicts when applying changes from the
      publisher occurred before the upgrade. Additionally, immediately after the
      upgrade, the vacuum may remove the deleted rows that are required for
      conflict detection. This can affect the changes that were not replicated
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index 9e8300fb9f6..456719383dc 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -216,13 +216,11 @@ main(int argc, char **argv)
 	 * as it only retains the dead tuples. It is created here for consistency.
 	 * Note that the new conflict detection slot uses the latest transaction
 	 * ID as xmin, so it cannot protect dead tuples that existed before the
-	 * upgrade. Additionally, commit timestamps and origin data are not
-	 * preserved during the upgrade. So, even after creating the slot, the
-	 * upgraded subscriber may be unable to detect conflicts or log relevant
-	 * commit timestamps and origins when applying changes from the publisher
-	 * occurred before the upgrade especially if those changes were not
-	 * replicated. It can only protect tuples that might be deleted after the
-	 * new cluster starts.
+	 * upgrade. It means even after creating the slot, the upgraded subscriber
+	 * may be unable to detect update_deleted conflicts when applying changes
+	 * from the publisher occurred before the upgrade especially if those
+	 * changes were not replicated. It can only protect tuples that might be
+	 * deleted after the new cluster starts.
 	 */
 	if (migrate_logical_slots || old_cluster.sub_retain_dead_tuples)
 	{
-- 
2.50.1

