From: Dmitry Fomin Date: Fri, 4 Dec 2026 21:48:00 +0100 Subject: [PATCH v1] Publish local catalog_xmin in update_local_synced_slot When update_local_synced_slot() cannot copy the remote slot's LSNs and catalog_xmin directly because no serialized snapshot exists at the remote restart_lsn, it advances the local slot via LogicalSlotAdvanceAndCheckSnapState(). Local decoding can leave slot->data.catalog_xmin older than remote_slot->catalog_xmin, yet update_local_synced_slot() unconditionally published remote_slot->catalog_xmin into slot->effective_catalog_xmin. That violates the invariant that catalog_xmin is persisted before the in-memory horizon advances: - With hot_standby_feedback enabled, the standby feeds the inflated remote catalog_xmin back to the primary, which advances the physical slot's catalog_xmin and allows catalog tuples still needed locally to be vacuumed. - While effective_catalog_xmin exceeds data.catalog_xmin, DetermineSlotInvalidationCause() checks effective_catalog_xmin and fails to invalidate the slot on replayed cleanups whose conflict horizon lies between the two values. - A subsequent LogicalConfirmReceivedLocation() resets effective_catalog_xmin back to data.catalog_xmin, after which replayed catalog cleanups invalidate the synced slot with RS_INVAL_HORIZON. - Conversely, if local decoding advances data.catalog_xmin ahead of remote_slot->catalog_xmin, publishing remote_slot->catalog_xmin moves effective_catalog_xmin backward without holding ProcArrayLock. Fix by publishing slot->data.catalog_xmin instead of remote_slot->catalog_xmin. In the direct-copy branch both values are identical; in the local-decoding branch effective_catalog_xmin now stays consistent with what was saved to disk. Reported-by: Vamshidhar Poralla Reported-by: Dmitry Fomin --- src/backend/replication/logical/slotsync.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c --- a/src/backend/replication/logical/slotsync.c +++ b/src/backend/replication/logical/slotsync.c @@ -351,11 +351,15 @@ update_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid) * advance. We do not take ProcArrayLock or similar since we only advance * xmin here and there's not much harm done by a concurrent computation * missing that. + * + * Publish the local catalog_xmin saved above. Local decoding may leave it + * older than the remote slot's catalog_xmin. Publishing the remote value + * could allow removal of catalog tuples still needed locally. */ if (updated_xmin_or_lsn) { SpinLockAcquire(&slot->mutex); - slot->effective_catalog_xmin = remote_slot->catalog_xmin; + slot->effective_catalog_xmin = slot->data.catalog_xmin; SpinLockRelease(&slot->mutex); ReplicationSlotsComputeRequiredXmin(false);