From: Tom Lane Date: Tue, 24 May 2016 19:20:12 +0000 (-0400) Subject: Avoid consuming an XID during vac_truncate_clog(). X-Git-Tag: REL9_5_4~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a34c3dd50f661126ac51c794e63f7932fe657542;p=postgresql Avoid consuming an XID during vac_truncate_clog(). vac_truncate_clog() uses its own transaction ID as the comparison point in a sanity check that no database's datfrozenxid has already wrapped around "into the future". That was probably fine when written, but in a lazy vacuum we won't have assigned an XID, so calling GetCurrentTransactionId() causes an XID to be assigned when otherwise one would not be. Most of the time that's not a big problem ... but if we are hard up against the wraparound limit, consuming XIDs during antiwraparound vacuums is a very bad thing. Instead, use ReadNewTransactionId(), which not only avoids this problem but is in itself a better comparison point to test whether wraparound has already occurred. Report and patch by Alexander Korotkov. Back-patch to all versions. Report: --- diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index be89b9b86b..9759ae11a9 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -1050,7 +1050,7 @@ vac_truncate_clog(TransactionId frozenXID, TransactionId lastSaneFrozenXid, MultiXactId lastSaneMinMulti) { - TransactionId myXID = GetCurrentTransactionId(); + TransactionId nextXID = ReadNewTransactionId(); Relation relation; HeapScanDesc scan; HeapTuple tuple; @@ -1099,7 +1099,7 @@ vac_truncate_clog(TransactionId frozenXID, MultiXactIdPrecedes(lastSaneMinMulti, dbform->datminmxid)) bogus = true; - if (TransactionIdPrecedes(myXID, dbform->datfrozenxid)) + if (TransactionIdPrecedes(nextXID, dbform->datfrozenxid)) frozenAlreadyWrapped = true; else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID)) {