Skip to content

Commit 0557e17

Browse files
committed
Ignore invalidated slots while computing oldest catalog Xmin
Once a logical slot has acquired a catalog_xmin, it doesn't let go of it, even when invalidated by exceeding the max_slot_wal_keep_size, which means that dead catalog tuples are not removed by vacuum anymore since the point is invalidated, until the slot is dropped. This could be catastrophic if catalog churn is high. Change the computation of Xmin to ignore invalidated slots, to prevent dead rows from accumulating. Backpatch to 13, where slot invalidation appeared. Author: Sirisha Chamarthi <sirichamarthi22@gmail.com> Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Discussion: https://postgr.es/m/CAKrAKeUEDeqquN9vwzNeG-CN8wuVsfRYbeOUV9qKO_RHok=j+g@mail.gmail.com
1 parent 92daeca commit 0557e17

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/backend/replication/slot.c

+7
Original file line numberDiff line numberDiff line change
@@ -847,15 +847,22 @@ ReplicationSlotsComputeRequiredXmin(bool already_locked)
847847
ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i];
848848
TransactionId effective_xmin;
849849
TransactionId effective_catalog_xmin;
850+
bool invalidated;
850851

851852
if (!s->in_use)
852853
continue;
853854

854855
SpinLockAcquire(&s->mutex);
855856
effective_xmin = s->effective_xmin;
856857
effective_catalog_xmin = s->effective_catalog_xmin;
858+
invalidated = (!XLogRecPtrIsInvalid(s->data.invalidated_at) &&
859+
XLogRecPtrIsInvalid(s->data.restart_lsn));
857860
SpinLockRelease(&s->mutex);
858861

862+
/* invalidated slots need not apply */
863+
if (invalidated)
864+
continue;
865+
859866
/* check the data xmin */
860867
if (TransactionIdIsValid(effective_xmin) &&
861868
(!TransactionIdIsValid(agg_xmin) ||

src/backend/storage/ipc/procarray.c

+3
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,9 @@ ProcArraySetReplicationSlotXmin(TransactionId xmin, TransactionId catalog_xmin,
39013901

39023902
if (!already_locked)
39033903
LWLockRelease(ProcArrayLock);
3904+
3905+
elog(DEBUG1, "xmin required by slots: data %u, catalog %u",
3906+
xmin, catalog_xmin);
39043907
}
39053908

39063909
/*

0 commit comments

Comments
 (0)