diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 3242abc4c15..52c4c654061 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -484,6 +484,7 @@ vacuum_set_xid_limits(Relation rel, int effective_multixact_freeze_max_age; TransactionId limit; TransactionId safeLimit; + MultiXactId oldestMxact; MultiXactId mxactLimit; MultiXactId safeMxactLimit; @@ -560,7 +561,8 @@ vacuum_set_xid_limits(Relation rel, Assert(mxid_freezemin >= 0); /* compute the cutoff multi, being careful to generate a valid value */ - mxactLimit = GetOldestMultiXactId() - mxid_freezemin; + oldestMxact = GetOldestMultiXactId(); + mxactLimit = oldestMxact - mxid_freezemin; if (mxactLimit < FirstMultiXactId) mxactLimit = FirstMultiXactId; @@ -574,7 +576,11 @@ vacuum_set_xid_limits(Relation rel, ereport(WARNING, (errmsg("oldest multixact is far in the past"), errhint("Close open transactions with multixacts soon to avoid wraparound problems."))); - mxactLimit = safeMxactLimit; + /* Use the safe limit, unless an older mxact is still running */ + if (MultiXactIdPrecedes(oldestMxact, safeMxactLimit)) + mxactLimit = oldestMxact; + else + mxactLimit = safeMxactLimit; } *multiXactCutoff = mxactLimit;