On Fri, Jun 20, 2025 at 4:48 PM Zhijie Hou (Fujitsu)
<houzj.f...@fujitsu.com> wrote:
>
> Here is the V39 patch set which includes the following changes:
>

1.
-static void
-create_conflict_slot_if_not_exists(void)
+void
+ApplyLauncherCreateConflictDetectionSlot(void)

I am not so sure about adding ApplyLauncher in front of this function
name. I see most others exposed from this file add such a prefix, but
this one looks odd to me as it has nothing specific to the launcher,
though we use it in launcher? How about
CreateConflictDetectionSlot(void)?

2.
 static void
 create_logical_replication_slots(void)
 {
+ if (!count_old_cluster_logical_slots())
+ return;
+

Doing this count twice (once here and once at the caller of
create_logical_replication_slots) seems redundant.

Apart from the above, attached please find a diff patch atop 0001,
0002, 0003. I think the first three patches look in a reasonable shape
now, can we merge them (0001, 0002, 0003)?

-- 
With Regards,
Amit Kapila.
diff --git a/doc/src/sgml/logical-replication.sgml 
b/doc/src/sgml/logical-replication.sgml
index 4217a2e7dee..bfb9c2fb31c 100644
--- a/doc/src/sgml/logical-replication.sgml
+++ b/doc/src/sgml/logical-replication.sgml
@@ -2507,14 +2507,18 @@ CONTEXT:  processing remote data for replication origin 
"pg_16395" during "INSER
    </para>
 
    <para>
-    Note that commit timestamps and origin data are not preserved during the
-    upgrade. Consequently, even with
+    Commit timestamps and origin data are not preserved during the upgrade.
+    As a result, even if
     <link 
linkend="sql-createsubscription-params-with-retain-conflict-info"><literal>retain_conflict_info</literal></link>
-    enabled, the upgraded subscriber might be unable to detect conflicts or log
+    is enabled, the upgraded subscriber may be unable to detect conflicts or 
log
     relevant commit timestamps and origins when applying changes from the
-    publisher occurring before or during the upgrade. To prevent this issue, 
the
-    user must ensure that all potentially conflicting changes are fully
-    replicated to the subscriber before proceeding with the upgrade.
+    publisher occurred before the upgrade especially if those changes were not
+    replicated. 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 before the upgrade. To ensure
+    consistent conflict tracking, users should ensure that all potentially
+    conflicting changes are replicated to the subscriber before initiating the
+    upgrade.
    </para>
 
    <para>
diff --git a/doc/src/sgml/ref/create_subscription.sgml 
b/doc/src/sgml/ref/create_subscription.sgml
index e5ba669e075..ed835032d27 100644
--- a/doc/src/sgml/ref/create_subscription.sgml
+++ b/doc/src/sgml/ref/create_subscription.sgml
@@ -463,11 +463,11 @@ CREATE SUBSCRIPTION <replaceable 
class="parameter">subscription_name</replaceabl
 
          <caution>
           <para>
-            Note that the information for conflict detection cannot be purged 
if
-            the subscription is disabled; thus, the information will accumulate
-            until the subscription is enabled. To prevent excessive 
accumulation,
-            it is recommended to disable 
<literal>retain_conflict_info</literal>
-            if the subscription will be inactive for an extended period.
+           Note that the information for conflict detection cannot be purged if
+           the subscription is disabled; thus, the information will accumulate
+           until the subscription is enabled. To prevent excessive 
accumulation,
+           it is recommended to disable <literal>retain_conflict_info</literal>
+           if the subscription will be inactive for an extended period.
           </para>
          </caution>
 
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 71314180535..5314e81390b 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -1966,7 +1966,10 @@ check_new_cluster_replication_slots(void)
        int                     i_nslots_on_new;
        int                     i_rci_slot_on_new;
 
-       /* Logical slots can be migrated since PG17. */
+       /*
+        * Logical slots can be migrated since PG17 and a physical slot
+        * CONFLICT_DETECTION_SLOT can be migrated sing PG19.
+        */
        if (GET_MAJOR_VERSION(old_cluster.major_version) <= 1600)
                return;
 
@@ -2159,7 +2162,7 @@ check_old_cluster_for_valid_slots(void)
                        /*
                         * The name "pg_conflict_detection" (defined as
                         * CONFLICT_DETECTION_SLOT) has been reserved for 
logical
-                        * replication conflict detection since PG18.
+                        * replication conflict detection slot since PG19.
                         */
                        if (strcmp(slot->slotname, "pg_conflict_detection") == 
0)
                        {
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index f6b967bc3a9..1b46293abc8 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -200,13 +200,25 @@ main(int argc, char **argv)
        check_ok();
 
        /*
-        * Migrate the logical slots to the new cluster.  Note that we need to 
do
-        * this after resetting WAL because otherwise the required WAL would be
-        * removed and slots would become unusable.  There is a possibility that
-        * background processes might generate some WAL before we could create 
the
-        * slots in the new cluster but we can ignore that WAL as that won't be
-        * required downstream. The conflict detection slots is not affected by
-        * these concerns, but is created here for consistency.
+        * Migrate replication slots to the new cluster.
+        *
+        * Note that we must migrate logical slots after resetting WAL because
+        * otherwise the required WAL would be removed and slots would become
+        * unusable.  There is a possibility that background processes might
+        * generate some WAL before we could create the slots in the new cluster
+        * but we can ignore that WAL as that won't be required downstream.
+        *
+        * The conflict detection slot is not affected by concerns related to
+        * WALs 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.
         */
        if (count_old_cluster_logical_slots() ||
                old_cluster.sub_retain_conflict_info)

Reply via email to