Skip to content

Commit 080cf32

Browse files
committed
Fix bug that could try to freeze running multixacts.
Commits 801c2dc and 801c2dc made it possible for vacuum to try to freeze a multixact that is still running. That was prevented by a check, but raised an error. Repair. Back-patch all the way. Author: Nathan Bossart, Jeremy Schneider Reported-by: Jeremy Schneider Reviewed-by: Jim Nasby, Thomas Munro Discussion: https://postgr.es/m/DAFB8AFF-2F05-4E33-AD7F-FF8B0F760C17%40amazon.com
1 parent bc3a94d commit 080cf32

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/backend/commands/vacuum.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ vacuum_set_xid_limits(Relation rel,
429429
int effective_multixact_freeze_max_age;
430430
TransactionId limit;
431431
TransactionId safeLimit;
432+
MultiXactId oldestMxact;
432433
MultiXactId mxactLimit;
433434
MultiXactId safeMxactLimit;
434435

@@ -504,7 +505,8 @@ vacuum_set_xid_limits(Relation rel,
504505
Assert(mxid_freezemin >= 0);
505506

506507
/* compute the cutoff multi, being careful to generate a valid value */
507-
mxactLimit = GetOldestMultiXactId() - mxid_freezemin;
508+
oldestMxact = GetOldestMultiXactId();
509+
mxactLimit = oldestMxact - mxid_freezemin;
508510
if (mxactLimit < FirstMultiXactId)
509511
mxactLimit = FirstMultiXactId;
510512

@@ -518,7 +520,11 @@ vacuum_set_xid_limits(Relation rel,
518520
ereport(WARNING,
519521
(errmsg("oldest multixact is far in the past"),
520522
errhint("Close open transactions with multixacts soon to avoid wraparound problems.")));
521-
mxactLimit = safeMxactLimit;
523+
/* Use the safe limit, unless an older mxact is still running */
524+
if (MultiXactIdPrecedes(oldestMxact, safeMxactLimit))
525+
mxactLimit = oldestMxact;
526+
else
527+
mxactLimit = safeMxactLimit;
522528
}
523529

524530
*multiXactCutoff = mxactLimit;

0 commit comments

Comments
 (0)