From fb5344c969af77bb78bc2a643fb75b9f8fea72dd Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 24 Jul 2019 20:24:07 +0300 Subject: Use full 64-bit XID for checking if a deleted GiST page is old enough. Otherwise, after a deleted page gets even older, it becomes unrecyclable again. B-tree has the same problem, and has had since time immemorial, but let's at least fix this in GiST, where this is new. Backpatch to v12, where GiST page deletion was introduced. Reviewed-by: Andrey Borodin Discussion: https://www.postgresql.org/message-id/835A15A5-F1B4-4446-A711-BF48357EB602%40yandex-team.ru --- src/backend/utils/time/snapmgr.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/backend/utils') diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index ef9fc15ac36..d07ca1b0b24 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -956,6 +956,36 @@ xmin_cmp(const pairingheap_node *a, const pairingheap_node *b, void *arg) return 0; } +/* + * Get current RecentGlobalXmin value, as a FullTransactionId. + */ +FullTransactionId +GetFullRecentGlobalXmin(void) +{ + FullTransactionId nextxid_full; + uint32 nextxid_epoch; + TransactionId nextxid_xid; + uint32 epoch; + + Assert(TransactionIdIsNormal(RecentGlobalXmin)); + + /* + * Compute the epoch from the next XID's epoch. This relies on the fact + * that RecentGlobalXmin must be within the 2 billion XID horizon from the + * next XID. + */ + nextxid_full = ReadNextFullTransactionId(); + nextxid_epoch = EpochFromFullTransactionId(nextxid_full); + nextxid_xid = XidFromFullTransactionId(nextxid_full); + + if (RecentGlobalXmin > nextxid_xid) + epoch = nextxid_epoch - 1; + else + epoch = nextxid_epoch; + + return FullTransactionIdFromEpochAndXid(epoch, RecentGlobalXmin); +} + /* * SnapshotResetXmin * -- cgit v1.2.3