Skip to content

Commit 583d86f

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 e86ece2 commit 583d86f

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
@@ -526,6 +526,7 @@ vacuum_set_xid_limits(Relation rel,
526526
int effective_multixact_freeze_max_age;
527527
TransactionId limit;
528528
TransactionId safeLimit;
529+
MultiXactId oldestMxact;
529530
MultiXactId mxactLimit;
530531
MultiXactId safeMxactLimit;
531532

@@ -602,7 +603,8 @@ vacuum_set_xid_limits(Relation rel,
602603
Assert(mxid_freezemin >= 0);
603604

604605
/* compute the cutoff multi, being careful to generate a valid value */
605-
mxactLimit = GetOldestMultiXactId() - mxid_freezemin;
606+
oldestMxact = GetOldestMultiXactId();
607+
mxactLimit = oldestMxact - mxid_freezemin;
606608
if (mxactLimit < FirstMultiXactId)
607609
mxactLimit = FirstMultiXactId;
608610

@@ -616,7 +618,11 @@ vacuum_set_xid_limits(Relation rel,
616618
ereport(WARNING,
617619
(errmsg("oldest multixact is far in the past"),
618620
errhint("Close open transactions with multixacts soon to avoid wraparound problems.")));
619-
mxactLimit = safeMxactLimit;
621+
/* Use the safe limit, unless an older mxact is still running */
622+
if (MultiXactIdPrecedes(oldestMxact, safeMxactLimit))
623+
mxactLimit = oldestMxact;
624+
else
625+
mxactLimit = safeMxactLimit;
620626
}
621627

622628
*multiXactCutoff = mxactLimit;

0 commit comments

Comments
 (0)