Hi,
On Tue, Nov17, 2026 at 01:35 AM Melanie Plageman wrote:
On Sat, Nov 14, 2026 at 8:08 AM Zhijie Hou <[email protected]> wrote:
>
> I just have one minor comment on the TAP test in 0001. IIUC, the
> pre-existing test in 034_create_database.pl was added by commit
> 8a8661828ae to verify that when CREATE DATABASE loads the template's
> pg_class into shared_buffers, it marks those buffers as permanent so
> that a subsequent checkpoint flushes them to disk.
>
> But with 0001, the modified test vacuuming tab_db_before_create_1 in
> template1 beforehand loads template1's pg_class into shared_buffers
> with BM_PERMANENT already set before CREATE DATABASE runs. If we
> want to keep the original regression coverage, maybe we could run
> the new test steps after the pre-existing test.
Ah, thanks so much for catching this. I read the test and not the
commit message adding it and thought it was just trying to make sure
that tables added after the copy didn't end up in the copied database
-- which, if I think about it, would have been a silly test. I've
changed it in attached v3 to retain the coverage in the initial test.
I also realized while editing this that I'll have to make a wrapper
version of CreateAndCopyRelationData() for the backports since it is
public. A bit annoying but I think better than the alternatives.
Thanks for updating the patch.
I think we also need to increase shared_buffers (e.g., to 16MB), because
$node->init(allows_streaming => 1) sets shared_buffers to 1MB
internally, causing the pg_class pages to be evicted from shared_buffers
before CREATE TABLE runs, so the test could not reach the old bug path.
BTW, while looking into why the wal_consistency_checking test didn't
catch this bug, I noticed that verifyBackupPageConsistency() also masks
out all the bits in VM pages via heap_mask() (somewhat similar to this
bug, since it treats pd_lower..pd_upper as unused space), so the
consistency check for VM pages always "passes". Once we avoid masking
the VM bitmap there (see the attached draft patch for reference), the
existing test catches this CREATE DB WAL_LOG bug right away:
PG_TEST_EXTRA=wal_consistency_checking meson test -C build
recovery/027_stream_regress
So if it's worth increasing the possibility of catching similar VM bugs,
maybe we could improve that as well (in a separate patch or thread).
--
Best Regards,
Zhijie Hou
From 4ede72e8ee6d79cda8209a725b1b6b04e07438a4 Mon Sep 17 00:00:00 2001
From: Zhijie Hou <[email protected]>
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 <sys/time.h>
#include <unistd.h>
+#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)