diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2016-05-24 15:20:12 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2016-05-24 15:20:12 -0400 |
commit | fe1731fca27008836f2208f4be8c22acf8ec1f67 (patch) | |
tree | 36ebd53e5fa48e3f3a6edd56308bf243f993edcb /src | |
parent | 7b40b2d90f44c1f4ef1bc130bd94decb15826676 (diff) | |
download | postgresql-fe1731fca27008836f2208f4be8c22acf8ec1f67.tar.gz postgresql-fe1731fca27008836f2208f4be8c22acf8ec1f67.zip |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/commands/vacuum.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index c5170efea50..15c36eca94f 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -784,7 +784,7 @@ vac_update_datfrozenxid(void) static void vac_truncate_clog(TransactionId frozenXID) { - TransactionId myXID = GetCurrentTransactionId(); + TransactionId nextXID = ReadNewTransactionId(); Relation relation; HeapScanDesc scan; HeapTuple tuple; @@ -816,7 +816,7 @@ vac_truncate_clog(TransactionId frozenXID) Assert(TransactionIdIsNormal(dbform->datfrozenxid)); - if (TransactionIdPrecedes(myXID, dbform->datfrozenxid)) + if (TransactionIdPrecedes(nextXID, dbform->datfrozenxid)) frozenAlreadyWrapped = true; else if (TransactionIdPrecedes(dbform->datfrozenxid, frozenXID)) { |