Fix bug that could try to freeze running multixacts.
authorThomas Munro <tmunro@postgresql.org>
Wed, 16 Oct 2019 20:59:21 +0000 (09:59 +1300)
committerThomas Munro <tmunro@postgresql.org>
Wed, 16 Oct 2019 21:28:28 +0000 (10:28 +1300)
Commits 801c2dc7 and 801c2dc7 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: http://postgr.es/m/DAFB8AFF-2F05-4E33-AD7F-FF8B0F760C17%40amazon.com

src/backend/commands/vacuum.c

index 44d500eab5579d40131c4d5b83fbf20c6f82c108..ebc76eaa2079d1d8111ce3ab12b53916c3a35a1b 100644 (file)
@@ -477,6 +477,7 @@ vacuum_set_xid_limits(Relation rel,
    int         effective_multixact_freeze_max_age;
    TransactionId limit;
    TransactionId safeLimit;
+   MultiXactId oldestMxact;
    MultiXactId mxactLimit;
    MultiXactId safeMxactLimit;
 
@@ -552,7 +553,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;
 
@@ -566,7 +568,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;