postgres.git / summary / log / commit / refs
commit aa40615cc99211db70429ebbc4c8a1549dcc06ae
Author: Amit Kapila <akapila@postgresql.org>
Date: Tue Jan 06 04:48:49 2026 +0000
First released in: 18.2
Update comments atop ReplicationSlotCreate.
Since commit 1462aad2e4, which introduced the ability to modify the
two_phase property of a slot, the comments above ReplicationSlotCreate
have become outdated. We have now added a cautionary note in the comments
above ReplicationSlotAlter explaining when it is safe to modify the
two_phase property of a slot.
Author: Daniil Davydov <3danissimo@gmail.com>
Author: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Backpatch-through: 18
Discussion: https://postgr.es/m/CAJDiXggZXQZ7bD0QcTizDt6us9aX6ZKK4dWxzgb5x3+TsVHjqQ@mail.gmail.com
src/backend/replication/slot.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 737508b33ee..4246d0a51e1 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -344,13 +344,7 @@ ReplicationSlotValidateNameInternal(const char *name, int *err_code,
* name: Name of the slot
* db_specific: logical decoding is db specific; if the slot is going to
* be used for that pass true, otherwise false.
- * two_phase: Allows decoding of prepared transactions. We allow this option
- * to be enabled only at the slot creation time. If we allow this option
- * to be changed during decoding then it is quite possible that we skip
- * prepare first time because this option was not enabled. Now next time
- * during getting changes, if the two_phase option is enabled it can skip
- * prepare because by that time start decoding point has been moved. So the
- * user will only get commit prepared.
+ * two_phase: If enabled, allows decoding of prepared transactions.
* failover: If enabled, allows the slot to be synced to standbys so
* that logical replication can be resumed after failover.
* synced: True if the slot is synchronized from the primary server.
@@ -868,6 +862,16 @@ ReplicationSlotDrop(const char *name, bool nowait)
/*
* Change the definition of the slot identified by the specified name.
+ *
+ * Altering the two_phase property of a slot requires caution on the
+ * client-side. Enabling it at any random point during decoding has the
+ * risk that transactions prepared before this change may be skipped by
+ * the decoder, leading to missing prepare records on the client. So, we
+ * enable it for subscription related slots only once the initial tablesync
+ * is finished. See comments atop worker.c. Disabling it is safe only when
+ * there are no pending prepared transaction, otherwise, the changes of
+ * already prepared transactions can be replicated again along with their
+ * corresponding commit leading to duplicate data or errors.
*/
void
ReplicationSlotAlter(const char *name, const bool *failover,
[parent: bea57a6b430c]