From a7bd8c40b60bd550b3fdac6216c8d6bd1ed972ee Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Mon, 2 Feb 2026 14:03:57 +0800 Subject: [PATCH v3 1/2] walsender: Assert MyReplicationSlot is set before use Author: Chao Li Reviewed-by: Zhijie Hou Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/6E7BD4F7-C22A-4B6C-A9BD-62877390DF86@gmail.com --- src/backend/replication/logical/logical.c | 2 +- src/backend/replication/walsender.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 85060d19a49..60c1e15db34 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -509,7 +509,7 @@ CreateDecodingContext(XLogRecPtr start_lsn, if (SlotIsPhysical(slot)) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), - errmsg("cannot use physical replication slot for logical decoding"))); + errmsg("cannot use a physical replication slot for logical decoding"))); /* * We need to access the system tables during decoding to build the diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index a0e6a3d200c..241e602feb4 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1464,6 +1464,11 @@ StartLogicalReplication(StartReplicationCmd *cmd) Assert(!MyReplicationSlot); + /* + * Acquire the replication slot and assign it to MyReplicationSlot. + * Verification that the slot is logical is deferred to + * CreateDecodingContext(). + */ ReplicationSlotAcquire(cmd->slotname, true, true); /* @@ -1765,6 +1770,8 @@ NeedToWaitForStandbys(XLogRecPtr flushed_lsn, uint32 *wait_event) int elevel = got_STOPPING ? ERROR : WARNING; bool failover_slot; + Assert(MyReplicationSlot); + failover_slot = (replication_active && MyReplicationSlot->data.failover); /* -- 2.50.1 (Apple Git-155)