From 1f88078b43b0c1bf16679c3de92a9f799fbec13f Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Sun, 4 Oct 2026 16:08:45 +0000 Subject: [PATCH v1] Show effective xmin in pg_replication_slots when xmin is unset. Previously, pg_replication_slots reported only the xmin saved to disk with the slot, which logical slots never set. While a logical slot is being created with an exported or used snapshot, it holds back the data xmin through its in-memory effective xmin alone, because that pin need not survive a crash, so the view showed no xmin for a slot that was holding one back. The slot creation waits for the transactions with an assigned XID that are running when it starts, so a long running or prepared transaction can keep a slot in this state for a long time. In PG19 and later, REPACK (CONCURRENTLY) keeps its slot in this state for the whole command. Fix this by reporting the effective xmin when the saved xmin is not set. Outside these cases the two differ only for a moment while a new value is being saved. The same is not needed for catalog_xmin, which is never unset while its effective value is set. Author: Bharath Rupireddy Discussion: https://postgr.es/m/<> Backpatch-through: 14 --- src/backend/replication/slotfuncs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index fdeb6a23d7b..fee69419c22 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -327,8 +327,15 @@ pg_get_replication_slots(PG_FUNCTION_ARGS) else nulls[i++] = true; + /* + * A logical slot being created with an exported or used snapshot + * holds back the data xmin through its in-memory effective xmin + * alone. See CreateInitDecodingContext(). + */ if (slot_contents.data.xmin != InvalidTransactionId) values[i++] = TransactionIdGetDatum(slot_contents.data.xmin); + else if (slot_contents.effective_xmin != InvalidTransactionId) + values[i++] = TransactionIdGetDatum(slot_contents.effective_xmin); else nulls[i++] = true; -- 2.47.3