Subject: pgsql: Fix race in ReplicationSlotRelease() for ephemeral slots

From: Fujii Masao <[email-masked]>
Date: Wed, 03 Jun 2026 09:49:13 +0000

Fix race in ReplicationSlotRelease() for ephemeral slots

When releasing an ephemeral replication slot, ReplicationSlotRelease()
drops the slot via ReplicationSlotDropAcquired().

However, after dropping the slot, ReplicationSlotRelease() continued
to use its local "slot" pointer, which still referenced the dropped
slot's former shared-memory entry. It could then update fields such as
effective_xmin in that entry.

Once an ephemeral slot has been dropped (via ReplicationSlotDropAcquired()),
its slot array entry can be reused immediately by another backend
creating a new slot. As a result, those updates could corrupt
the state of an unrelated replication slot.

Fix by skipping those shared-memory updates for phemeral slots and
performing them only for non-ephemeral slots, whose shared-memory
entries remain valid after release.

Backpatch to all supported versions.

Author: Zhijie Hou <[email-masked]>
Reviewed-by: Masao Fujii <[email-masked]>
Reviewed-by: Srinath Reddy Sadipiralla <[email-masked]>
Reviewed-by: Xuneng Zhou <[email-masked]>
Discussion: https://postgr.es/m/[email-masked]
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/080d61f07ce2852aff32b05aba5c417bad8859d2

Modified Files
--------------
src/backend/replication/slot.c | 76 ++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 37 deletions(-)