Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1ad033d

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 4f997ad commit 1ad033d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/backend/replication/slot.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,15 +846,22 @@ ReplicationSlotsComputeRequiredXmin(bool already_locked)
846846
ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i];
847847
TransactionId effective_xmin;
848848
TransactionId effective_catalog_xmin;
849+
bool invalidated;
849850

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

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

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

src/backend/storage/ipc/procarray.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,9 @@ ProcArraySetReplicationSlotXmin(TransactionId xmin, TransactionId catalog_xmin,
39003900

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

39053908
/*

0 commit comments

Comments
 (0)