diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-11-22 10:56:07 +0100 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2022-11-22 10:56:07 +0100 |
commit | 1ad033df16df8d9f9e9f597ca31915266dfbdfb9 (patch) | |
tree | 92bc56d572ed7c9a0c61128f0badcf536de3e3bf /src | |
parent | 4f997ad06255a2e2cb23c9ba1c30bf42ceb8fbb5 (diff) | |
download | postgresql-1ad033df16df8d9f9e9f597ca31915266dfbdfb9.tar.gz postgresql-1ad033df16df8d9f9e9f597ca31915266dfbdfb9.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/replication/slot.c | 7 | ||||
-rw-r--r-- | src/backend/storage/ipc/procarray.c | 3 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 329599e99de..80d96db8eb9 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -846,6 +846,7 @@ ReplicationSlotsComputeRequiredXmin(bool already_locked) ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i]; TransactionId effective_xmin; TransactionId effective_catalog_xmin; + bool invalidated; if (!s->in_use) continue; @@ -853,8 +854,14 @@ ReplicationSlotsComputeRequiredXmin(bool already_locked) SpinLockAcquire(&s->mutex); effective_xmin = s->effective_xmin; effective_catalog_xmin = s->effective_catalog_xmin; + invalidated = (!XLogRecPtrIsInvalid(s->data.invalidated_at) && + XLogRecPtrIsInvalid(s->data.restart_lsn)); SpinLockRelease(&s->mutex); + /* invalidated slots need not apply */ + if (invalidated) + continue; + /* check the data xmin */ if (TransactionIdIsValid(effective_xmin) && (!TransactionIdIsValid(agg_xmin) || diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index dadaa958a84..0d197210461 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -3900,6 +3900,9 @@ ProcArraySetReplicationSlotXmin(TransactionId xmin, TransactionId catalog_xmin, if (!already_locked) LWLockRelease(ProcArrayLock); + + elog(DEBUG1, "xmin required by slots: data %u, catalog %u", + xmin, catalog_xmin); } /* |