On Monday, February 17, 2025, Hayato Kuroda (Fujitsu) <
kuroda.hayato@fujitsu.com> wrote:
backend> SELECT pg_create_physical_replication_slot(slot_name := 'physical_slot', immediately_reserve := true);
Since this function releases the slot when it returns, re-acquisition, even by the same backend, must always re-associate MyProcPid to the named slot.
[1]:
```
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -599,7 +599,7 @@ retry:
SpinLockRelease(&s->mutex);
}
else
- active_pid = MyProcPid;
+ s->active_pid = active_pid = MyProcPid;
LWLockRelease(ReplicationSlotControlLock);
/*
```
This, but you cannot modify the slot without holding the spinlock.
I’d probably add an assert that the existing state of s->active_pid is either 0 or MyProcPid already. In single-user mode it mustn’t, really cannot, be anything else. But the failure here is because the SQL function does a slot release; there are probably other reasonable paths where the assignment of MyProcPid during slot creation is retained and encountered during a subsequent slot acquire.
David J.