Skip to content

Commit 068ca76

Browse files
hlinnakaRucha Kulkarni
authored andcommitted
Don't reset 'latest_page_number' when replaying multixid truncation
'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 (cherry picked from commit 4a36c89f1657e0c159a1dcef18f5da4f2cc9348f)
1 parent 8ad11f9 commit 068ca76

2 files changed

Lines changed: 3 additions & 11 deletions

File tree

src/backend/access/transam/multixact.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,6 @@ multixact_redo(XLogReaderState *record)
35713571
else if (info == XLOG_MULTIXACT_TRUNCATE_ID)
35723572
{
35733573
xl_multixact_truncate xlrec;
3574-
int64 pageno;
35753574

35763575
memcpy(&xlrec, XLogRecGetData(record),
35773576
SizeOfMultiXactTruncate);
@@ -3596,15 +3595,6 @@ multixact_redo(XLogReaderState *record)
35963595
SetMultiXactIdLimit(xlrec.endTruncOff, xlrec.oldestMultiDB, false);
35973596

35983597
PerformMembersTruncation(xlrec.startTruncMemb, xlrec.endTruncMemb);
3599-
3600-
/*
3601-
* During XLOG replay, latest_page_number isn't necessarily set up
3602-
* yet; insert a suitable value to bypass the sanity test in
3603-
* SimpleLruTruncate.
3604-
*/
3605-
pageno = MultiXactIdToOffsetPage(xlrec.endTruncOff);
3606-
pg_atomic_write_u64(&MultiXactOffsetCtl->shared->latest_page_number,
3607-
pageno);
36083598
PerformOffsetsTruncation(xlrec.startTruncOff, xlrec.endTruncOff);
36093599

36103600
LWLockRelease(MultiXactTruncationLock);

src/include/access/slru.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ typedef struct SlruSharedData
110110
/*
111111
* latest_page_number is the page number of the current end of the log;
112112
* this is not critical data, since we use it only to avoid swapping out
113-
* the latest page.
113+
* the latest page. (An exception: an accurate latest_page_number is
114+
* needed on pg_multixact/offsets to replay WAL generated with older minor
115+
* versions correctly. See RecordNewMultiXact().)
114116
*/
115117
pg_atomic_uint64 latest_page_number;
116118

0 commit comments

Comments
 (0)