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 <[email protected]> Author: Ke <[email protected]> Author: Rajesh Kumar Thandapani <[email protected]> Reviewed-by: Raja Sai Pranav <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/[email protected] Discussion: https://postgr.es/m/cajoz81s07r3akkkp-nj8sgqnocm0nu24g3hz0fxtsy1oqsg...@mail.gmail.com Backpatch-through: 17 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/47abddc25841147d4bb1743ca6bd51ac3c311fa3 Modified Files -------------- src/bin/pg_combinebackup/reconstruct.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
