]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Don't reset 'latest_page_number' when replaying multixid truncation
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 16 Feb 2026 15:16:59 +0000 (17:16 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 16 Feb 2026 15:16:59 +0000 (17:16 +0200)
'latest_page_number' is set to the correct value, according to
nextOffset, early at system startup. Contrary to the comment, it hence
should be set up correctly by the time we get to WAL replay.

This fixes a failure to replay WAL generated on older minor versions,
before commit 789d65364c (18.2, 17.8, 16.12, 15.16, 14.21). The
failure occurs after a truncation record has been replayed and looks
like this:

    FATAL:  could not access status of transaction 858112
    DETAIL:  Could not read from file "pg_multixact/offsets/000D" at offset 24576: read too few bytes.
    CONTEXT:  WAL redo at 3/2A3AB408 for MultiXact/CREATE_ID: 858111 offset 6695072 nmembers 5: 1048228 (sh) 1048271 (keysh) 1048316 (sh) 1048344 (keysh) 1048370 (sh)

Reported-by: Sebastian Webber <sebastian@swebber.me>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Discussion: https://www.postgresql.org/message-id/20260214090150.GC2297@p46.dedyn.io;lightning.p46.dedyn.io
Backpatch-through: 14-18

src/backend/access/transam/multixact.c
src/include/access/slru.h

index d5ac2d873802cd7de98e6c62622add8f815f31e0..08a1d08b547217352e5696ab7019101d52bc7606 100644 (file)
@@ -3577,7 +3577,6 @@ multixact_redo(XLogReaderState *record)
        else if (info == XLOG_MULTIXACT_TRUNCATE_ID)
        {
                xl_multixact_truncate xlrec;
-               int64           pageno;
 
                memcpy(&xlrec, XLogRecGetData(record),
                           SizeOfMultiXactTruncate);
@@ -3602,15 +3601,6 @@ multixact_redo(XLogReaderState *record)
                SetMultiXactIdLimit(xlrec.endTruncOff, xlrec.oldestMultiDB, false);
 
                PerformMembersTruncation(xlrec.startTruncMemb, xlrec.endTruncMemb);
-
-               /*
-                * During XLOG replay, latest_page_number isn't necessarily set up
-                * yet; insert a suitable value to bypass the sanity test in
-                * SimpleLruTruncate.
-                */
-               pageno = MultiXactIdToOffsetPage(xlrec.endTruncOff);
-               pg_atomic_write_u64(&MultiXactOffsetCtl->shared->latest_page_number,
-                                                       pageno);
                PerformOffsetsTruncation(xlrec.startTruncOff, xlrec.endTruncOff);
 
                LWLockRelease(MultiXactTruncationLock);
index d5ca3447208155d00d497fbc40fdc2a960a58882..f8bf1f1430f4aaf9b2cdadd9f0e9caa887a72608 100644 (file)
@@ -110,7 +110,9 @@ typedef struct SlruSharedData
        /*
         * latest_page_number is the page number of the current end of the log;
         * this is not critical data, since we use it only to avoid swapping out
-        * the latest page.
+        * the latest page.  (An exception: an accurate latest_page_number is
+        * needed on pg_multixact/offsets to replay WAL generated with older minor
+        * versions correctly.  See RecordNewMultiXact().)
         */
        pg_atomic_uint64 latest_page_number;