Commit 996d2739 authored by Tom Lane's avatar Tom Lane

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: <CAPpHfdspOkmiQsxh-UZw2chM6dRMwXAJGEmmbmqYR=yvM7-s6A@mail.gmail.com>
parent 0c7cd45b
...@@ -1051,7 +1051,7 @@ vac_truncate_clog(TransactionId frozenXID, ...@@ -1051,7 +1051,7 @@ vac_truncate_clog(TransactionId frozenXID,
TransactionId lastSaneFrozenXid, TransactionId lastSaneFrozenXid,
MultiXactId lastSaneMinMulti) MultiXactId lastSaneMinMulti)
{ {
TransactionId myXID = GetCurrentTransactionId(); TransactionId nextXID = ReadNewTransactionId();
Relation relation; Relation relation;
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple tuple; HeapTuple tuple;
...@@ -1100,7 +1100,7 @@ vac_truncate_clog(TransactionId frozenXID, ...@@ -1100,7 +1100,7 @@ vac_truncate_clog(TransactionId frozenXID,
MultiXactIdPrecedes(lastSaneMinMulti, dbform->datminmxid)) MultiXactIdPrecedes(lastSaneMinMulti, dbform->datminmxid))
bogus = true; bogus = true;
if (TransactionIdPrecedes(myXID, dbform->datfrozenxid)) if (TransactionIdPrecedes(nextXID, dbform->datfrozenxid))
frozenAlreadyWrapped = true; frozenAlreadyWrapped = true;
else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID)) else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment