From 4ede72e8ee6d79cda8209a725b1b6b04e07438a4 Mon Sep 17 00:00:00 2001 From: Zhijie Hou Date: Tue, 17 Nov 2026 22:06:38 +0800 Subject: [PATCH v1 1/2] Fix WAL consistency checking for visibility map pages. Both RM_HEAP_ID and RM_HEAP2_ID WAL records register VISIBILITYMAP_FORKNUM buffers (since a507b86900f for VM-setting records, and since ed62d26caca for VM-clearing records). When wal_consistency_checking is enabled for heap or heap2, verifyBackupPageConsistency() previously passed every registered block to rmgr.rm_mask (heap_mask()) without checking forknum. Because a visibility map page is initialized with PageInit(page, BLCKSZ, 0) and stores its bitmap between pd_lower (SizeOfPageHeaderData) and pd_upper (BLCKSZ), mask_unused_space() in heap_mask() zeroed out the entire bitmap in both the WAL backup image and the replay image before comparing them. Consequently, wal_consistency_checking silently missed visibility map page divergences during WAL replay. Fix verifyBackupPageConsistency() to mask only the page LSN and checksum when forknum is VISIBILITYMAP_FORKNUM, avoiding an ABI break to RmgrData.rm_mask. --- src/backend/access/transam/xlogrecovery.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c index 52ac6d58423..490e51f26e5 100644 --- a/src/backend/access/transam/xlogrecovery.c +++ b/src/backend/access/transam/xlogrecovery.c @@ -30,6 +30,7 @@ #include #include +#include "access/bufmask.h" #include "access/timeline.h" #include "access/transam.h" #include "access/xact.h" @@ -2547,10 +2548,21 @@ verifyBackupPageConsistency(XLogReaderState *record) errmsg_internal("%s", record->errormsg_buf))); /* - * If masking function is defined, mask both the primary and replay - * images + * Mask both the primary and replay images before comparing them. + * + * Visibility map pages are modified by RM_HEAP_ID and RM_HEAP2_ID + * records, but do not follow the standard heap page layout: their + * bitmap occupies the bytes between pd_lower and pd_upper (see + * visibilitymap.c), which heap_mask() would wipe via + * mask_unused_space(). Only the LSN and checksum can legitimately + * differ on a visibility map page. */ - if (rmgr.rm_mask != NULL) + if (forknum == VISIBILITYMAP_FORKNUM) + { + mask_page_lsn_and_checksum(replay_image_masked); + mask_page_lsn_and_checksum(primary_image_masked); + } + else if (rmgr.rm_mask != NULL) { rmgr.rm_mask(replay_image_masked, blkno); rmgr.rm_mask(primary_image_masked, blkno); -- 2.54.0 (Apple Git-157)