postgres.git / summary / log / commit / refs

commit    67fa8cb33cd94c6d6e17dc64b3748e9d70bb145c
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Mon Nov 02 23:39:20 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    Delay checkpoint start while creating a multixact
    
    A checkpoint starting between the CREATE_ID record and the SLRU update
    could lose the multixact after a crash.
    
    Author: shihao zhong <zhong950419@gmail.com>
    Discussion: https://www.postgresql.org/message-id/CAGRkXqSuiJ_X4+Z6rsD42pcuACnD9PhoQ-Os+mUJNmJarBWkNg@mail.gmail.com
    Backpatch-through: 14


src/backend/access/transam/multixact.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index 50c8d9220e1..4ed5246900e 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -834,6 +834,16 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members) */ multi = GetNewMultiXactId(nmembers, &offset); + /* + * Prevent checkpoints from starting between the WAL record and the update + * of the OFFSETs and MEMBERs pages. Otherwise the checkpoint could flush + * the pages before they hold the new multixact, while recovery after a + * crash would begin after the WAL record, and the multixact would be lost + * even though data pages might already refer to it. + */ + Assert(!MyProc->delayChkpt); + MyProc->delayChkpt = true; + /* Make an XLOG entry describing the new MXID. */ xlrec.mid = multi; xlrec.moff = offset; @@ -854,6 +864,8 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members) /* Now enter the information into the OFFSETs and MEMBERs logs */ RecordNewMultiXact(multi, offset, nmembers, members); + MyProc->delayChkpt = false; + /* Done with critical section */ END_CRIT_SECTION(); [parent: c48577385d15]