8000 Avoid consuming an XID during vac_truncate_clog(). · rtpg/postgres@fe1731f · GitHub
[go: up one dir, main page]

Skip to content

Commit fe1731f

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 7b40b2d commit fe1731f

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
@@ -784,7 +784,7 @@ vac_update_datfrozenxid(void)
784784
static void
785785
vac_truncate_clog(TransactionId frozenXID)
786786
{
787-
TransactionId myXID = GetCurrentTransactionId();
787+
TransactionId nextXID = ReadNewTransactionId();
788788
Relation relation;
789789
HeapScanDesc scan;
790790
HeapTuple tuple;
@@ -816,7 +816,7 @@ vac_truncate_clog(TransactionId frozenXID)
816816

817817
Assert(TransactionIdIsNormal(dbform->datfrozenxid));
818818

819-
if (TransactionIdPrecedes(myXID, dbform->datfrozenxid))
819+
if (TransactionIdPrecedes(nextXID, dbform->datfrozenxid))
820820
frozenAlreadyWrapped = true;
821821
else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID))
822822
{

0 commit comments

Comments
 (0)
0