pgsql: Fix pg_combinebackup handling of intermediate truncations

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix pg_combinebackup handling of intermediate truncations
Date: 2026-11-19 07:12:07
Message-ID: E1xTwJS-00000000LqL-1KxR@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix pg_combinebackup handling of intermediate truncations

Restoring a backup with pg_combinebackup could bring back deleted
rows and leave tables inconsistent with their indexes. This could
happen when a relation was truncated before an intermediate
incremental backup and later extended with zero-filled pages that
were not recorded in WAL, as can occur during bulk relation extension
by COPY.

The problem was that pg_combinebackup used only the latest
incremental file's truncation_block_length to determine which blocks
could be copied from earlier backups. It ignored smaller truncation
limits in intermediate backups, allowing stale blocks from before a
truncation to be copied into pages that should have been zero-filled.

Fix this by tracking the truncation limit while walking backward
through the backup chain, lowering it after processing each incremental
file's own blocks. This prevents older backups from supplying blocks
at or beyond the limit while preserving blocks supplied by newer backups.

Backpatch to 17, where incremental backup was introduced.

Reported-by: Ke <kehan5800(at)gmail(dot)com>
Author: Ke <kehan5800(at)gmail(dot)com>
Author: Rajesh Kumar Thandapani <rajeshkumarth(at)google(dot)com>
Reviewed-by: Raja Sai Pranav <rajasaipranav0(at)gmail(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/19776-c9e815f92ff29628@postgresql.org
Discussion: https://postgr.es/m/CAJoZ81s07r3akkKp-nJ8sgQNoCM0nu24g3HZ0FxTSY1OqsgurQ@mail.gmail.com
Backpatch-through: 17

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/459595e3270d26cc0bc9b78602db1db4b82002af

Modified Files
--------------
src/bin/pg_combinebackup/reconstruct.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-11-19 07:12:17 pgsql: Fix pg_combinebackup handling of intermediate truncations
Previous Message Fujii Masao 2026-11-19 07:11:57 pgsql: Fix pg_combinebackup handling of intermediate truncations