postgres.git / summary / log / commit / refs
commit 31538e165a91ac1f031d818dac2bd8ea83e3479c
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 494fb196eef..23ed361703e 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -919,6 +919,16 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
INJECTION_POINT_CACHED("multixact-create-from-members", NULL);
+ /*
+ * 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->delayChkptFlags & DELAY_CHKPT_START) == 0);
+ MyProc->delayChkptFlags |= DELAY_CHKPT_START;
+
/* Make an XLOG entry describing the new MXID. */
xlrec.mid = multi;
xlrec.moff = offset;
@@ -939,6 +949,8 @@ MultiXactIdCreateFromMembers(int nmembers, MultiXactMember *members)
/* Now enter the information into the OFFSETs and MEMBERs logs */
RecordNewMultiXact(multi, offset, nmembers, members);
+ MyProc->delayChkptFlags &= ~DELAY_CHKPT_START;
+
/* Done with critical section */
END_CRIT_SECTION();
[parent: 1be7010d1bae]