Fix stale visibility maps in incremental backups after heap truncation An incremental backup taken after VACUUM truncates a table can restore stale visibility map bits when both data checksums and wal_log_hints are disabled. If the restored table grows again, the stale bits can cause VACUUM to skip required freezing and advance relfrozenxid past unfrozen tuples, or cause index-only scans to return deleted rows.
Heap truncation clears bits for removed heap pages in the last remaining VM page. With both settings disabled, that page is not separately WAL-logged. The WAL summarizer records the VM truncation limit but does not mark the remaining page as modified, allowing incremental backups to reuse its old contents. The truncation record precedes the incremental backup's start LSN, so recovery does not replay it to clear those bits. Fix this by marking the last remaining VM page as modified when summarizing a truncation record, so incremental backups include its current contents. Do this conservatively even when truncation falls on a VM page boundary and the remaining page does not need to change. Note that existing WAL summaries are not regenerated by this fix. Incremental backups taken after updating can therefore still be affected if they use summaries generated before the fix. Take a new full backup from an uncorrupted server after updating and use it as the basis for subsequent incremental backups. This does not repair existing backups or corruption already present in a restored database. Backpatch to PostgreSQL 17, where incremental backup was introduced. Bug: #19775 Author: Ke <[email protected]> Co-authored-by: Fujii Masao <[email protected]> Co-authored-by: Shihao Zhong <[email protected]> Discussion: https://postgr.es/m/[email protected] Discussion: https://postgr.es/m/cagrkxqsnghf+wbyp-pdfjvlfbejjg3cvzd9hn-gxsvcwj2f...@mail.gmail.com Backpatch-through: 17 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/dde54ecde2f8ac10504ac2221b45d1ccdb73352d Modified Files -------------- src/backend/postmaster/walsummarizer.c | 19 +++++- src/bin/pg_combinebackup/meson.build | 1 + src/bin/pg_combinebackup/t/014_vm_truncation.pl | 85 +++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-)
