v3-0001-Improve-the-documentation-for-pg_copy_logical_rep.patch
application/octet-stream
Filename: v3-0001-Improve-the-documentation-for-pg_copy_logical_rep.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch v3-0001
Subject: Improve the documentation for pg_copy_logical_replication_slot
| File | + | − |
|---|---|---|
| doc/src/sgml/func.sgml | 3 | 0 |
| src/backend/replication/slotfuncs.c | 12 | 7 |
From 94d10dabc00b13624909b0b658ef9201118a3b52 Mon Sep 17 00:00:00 2001
From: Hou Zhijie <houzj.fnst@cn.fujitsu.com>
Date: Mon, 24 Feb 2025 15:36:11 +0800
Subject: [PATCH v3 1/2] Improve the documentation for
pg_copy_logical_replication_slot
This commit documents that the failover option is not copied when using the
pg_copy_logical_replication_slot function, and it defaults to false.
Additionally, the comments within the function is improved to provide a clear
explanation of the reason behind this behavior.
---
doc/src/sgml/func.sgml | 3 +++
src/backend/replication/slotfuncs.c | 19 ++++++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 9f60a476eb..a29c9500ba 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -29374,6 +29374,9 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
from the same <acronym>LSN</acronym> as the source logical slot. Both
<parameter>temporary</parameter> and <parameter>plugin</parameter> are
optional; if they are omitted, the values of the source slot are used.
+ The <parameter>failover</parameter> option of source logical slot is
+ not copied and is set to <literal>false</literal> by default to avoid
+ potential issues with the slot synchronization.
</para></entry>
</row>
diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c
index f652ec8a73..8222e5a109 100644
--- a/src/backend/replication/slotfuncs.c
+++ b/src/backend/replication/slotfuncs.c
@@ -695,13 +695,18 @@ copy_replication_slot(FunctionCallInfo fcinfo, bool logical_slot)
* hence pass find_startpoint false. confirmed_flush will be set
* below, by copying from the source slot.
*
- * To avoid potential issues with the slot synchronization where the
- * restart_lsn of a replication slot can go backward, we set the
- * failover option to false here. This situation occurs when a slot
- * on the primary server is dropped and immediately replaced with a
- * new slot of the same name, created by copying from another existing
- * slot. However, the slot synchronization will only observe the
- * restart_lsn of the same slot going backward.
+ * Copying the failover option is not allowed to prevent potential
+ * issues with slot synchronization. For instance, if a slot was
+ * synchronized to the standby, then dropped on the primary, and
+ * immediately recreated by copying from another existing slot with
+ * much earlier restart_lsn and confirmed_flush_lsn, the slot
+ * synchronization would only observe the LSN of the same slot moving
+ * backward. As slot synchronization does not copy the restart_lsn and
+ * confirmed_flush_lsn backward (see update_local_synced_slot() for
+ * details), if a failover happens before the primary's slot catches
+ * up, logical replication cannot continue using the synchronized slot
+ * on the promoted standby because the slot retains the restart_lsn and
+ * confirmed_flush_lsn that are much later than expected.
*/
create_logical_replication_slot(NameStr(*dst_name),
plugin,
--
2.30.0.windows.2