pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix stale visibility maps in incremental backups after heap trun
Date: Thu, 05 Nov 2026 09:09:02 +0000
Message-ID: <E1xOtSx-00000000Hza-15eA@gemulon.postgresql.org> (raw)

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 <kehan5800@gmail.com>
Co-authored-by: Fujii Masao <masao.fujii@gmail.com>
Co-authored-by: Shihao Zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/19775-087aebfa1a709b09@postgresql.org
Discussion: https://postgr.es/m/CAGRkXqSnghF+wbyP-PdfjVLfbejJG3cvZd9hN-gxsvCWj2F64Q@mail.gmail.com
Backpatch-through: 17

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0733c72198c9d49b239703a01d9fb5ecba7d04fb

Modified Files
--------------
src/backend/postmaster/walsummarizer.c          | 19 +++++-
src/bin/pg_combinebackup/meson.build            |  1 +
src/bin/pg_combinebackup/t/014_vm_truncation.pl | 90 +++++++++++++++++++++++++
3 files changed, 108 insertions(+), 2 deletions(-)



view thread (4+ messages)

Message-ID: <E1xOtSx-00000000Hza-15eA@gemulon.postgresql.org>
Permalink:  ../E1xOtSx-00000000Hza-15eA@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xOtSx-00000000Hza-15eA@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org
  Subject: Re: pgsql: Fix stale visibility maps in incremental backups after heap trun
  In-Reply-To: <E1xOtSx-00000000Hza-15eA@gemulon.postgresql.org>
  References: <E1xOtSx-00000000Hza-15eA@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox