From c4d68e50f15983b511a959dbbe3a49c1663f3d0d Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Mon, 2 Feb 2026 14:03:57 +0800
Subject: [PATCH v2 1/2] walsender: Assert MyReplicationSlot is set before use

Author: Chao Li <lic@highgo.com>
Reviewed-by: Zhijie Hou <houzj.fnst@fujitsu.com>
Discussion: https://postgr.es/m/6E7BD4F7-C22A-4B6C-A9BD-62877390DF86@gmail.com
---
 src/backend/replication/walsender.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index a0e6a3d200c..30d6fa6cedf 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -1465,6 +1465,10 @@ StartLogicalReplication(StartReplicationCmd *cmd)
 	Assert(!MyReplicationSlot);
 
 	ReplicationSlotAcquire(cmd->slotname, true, true);
+	if (!SlotIsLogical(MyReplicationSlot))
+		ereport(ERROR,
+				(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+				 errmsg("cannot use a physical replication slot for logical replication")));
 
 	/*
 	 * Force a disconnect, so that the decoding code doesn't need to care
@@ -1765,6 +1769,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)

