]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix VM clear WAL logging by registering VM blocks
authorMelanie Plageman <melanieplageman@gmail.com>
Wed, 15 Jul 2026 21:24:49 +0000 (17:24 -0400)
committerMelanie Plageman <melanieplageman@gmail.com>
Wed, 15 Jul 2026 21:24:49 +0000 (17:24 -0400)
commited62d26cacac96ca5c6b4e6fcc5308b11a8371c8
tree02ac1bb2c8af271df88bc96d0b77906abc477367
parent2340fb8f02b28d2fe7f0023d84c3055a38cd5b9e
Fix VM clear WAL logging by registering VM blocks

Heap WAL records that clear bits on the visibility map (like inserts and
deletes) did not register the visibility map blocks they modified.
Because the WAL summarizer only records registered blocks, an
incremental backup taken over such operations would omit the changed VM
pages. On restore, the VM would retain stale all-visible/all-frozen
bits, which can cause wrong results from index-only scans and incorrect
relfrozenxid advancement due to vacuum page skipping.

Not registering the VM buffer also meant we never emitted FPIs of VM
pages when clearing bits. A torn VM page won't raise an error because
the VM is read with ZERO_ON_ERROR; with checksums on, it would be
detected and zeroed, but with checksums off, it is accepted as-is and
can lead to data corruption.

Fix this by registering the VM buffer in the WAL record when clearing VM
bits. The VM buffer must now be locked throughout the critical section
that modifies the VM and heap pages and emits the WAL record. This can
slow down operations that clear the VM, since the VM lock is held longer
and VM FPIs may be emitted, but it is required for correctness.

Note that this fix does not repair existing incremental backups.

Bumps XLOG_PAGE_MAGIC.

Author: Melanie Plageman <melanieplageman@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Discussion: https://postgr.es/m/flat/CAAKRu_bn%2Be7F4yPFBgFbnP%2BsyJRKyNK092bjD2LKvZW7O4Svag>
Backpatch-through: 17
contrib/pg_surgery/heap_surgery.c
src/backend/access/heap/heapam.c
src/backend/access/heap/heapam_xlog.c
src/backend/access/heap/pruneheap.c
src/backend/access/heap/visibilitymap.c
src/bin/pg_walsummary/t/002_blocks.pl
src/include/access/heapam_xlog.h
src/include/access/xlog_internal.h