Skip to content

Commit a34c3dd

Browse files
committed
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>
1 parent e504d91 commit a34c3dd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/backend/commands/vacuum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ vac_truncate_clog(TransactionId frozenXID,
10501050
TransactionId lastSaneFrozenXid,
10511051
MultiXactId lastSaneMinMulti)
10521052
{
1053-
TransactionId myXID = GetCurrentTransactionId();
1053+
TransactionId nextXID = ReadNewTransactionId();
10541054
Relation relation;
10551055
HeapScanDesc scan;
10561056
HeapTuple tuple;
@@ -1099,7 +1099,7 @@ vac_truncate_clog(TransactionId frozenXID,
10991099
MultiXactIdPrecedes(lastSaneMinMulti, dbform->datminmxid))
11001100
bogus = true;
11011101

1102-
if (TransactionIdPrecedes(myXID, dbform->datfrozenxid))
1102+
if (TransactionIdPrecedes(nextXID, dbform->datfrozenxid))
11031103
frozenAlreadyWrapped = true;
11041104
else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID))
11051105
{

0 commit comments

Comments
 (0)