pgsql: Fix incremental backup data loss due to WAL summary merge order

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix incremental backup data loss due to WAL summary merge order
Date: 2026-11-01 15:27:11
Message-ID: E1xNXSh-00000001fgY-1f2Z@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix incremental backup data loss due to WAL summary merge order

An incremental backup taken after a relation is truncated and extended
again can omit modified blocks. Combining it with an earlier backup can
then restore stale data, causing live rows to disappear and deleted rows
to reappear.

WAL summaries were merged without ensuring LSN order. Applying a limit
block from an older summary after processing a newer summary could
discard references to blocks modified later, causing those blocks to
be omitted from the backup.

Sort the required summaries by ascending start LSN before merging them,
preserving references to later block modifications so that the required
blocks are included in the backup.

Backpatch to 17, where incremental backup was introduced.

Bug: #19774
Reported-by: Ke <kehan5800(at)gmail(dot)com>
Author: Ke <kehan5800(at)gmail(dot)com>
Co-authored-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/19774-8a1cbfd1774fcd0c%40postgresql.org
Backpatch-through: 17

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9e20db542b0ff5fdcb839e9b440db337c7f439a5

Modified Files
--------------
src/backend/backup/basebackup_incremental.c | 19 +++++
src/bin/pg_combinebackup/meson.build | 1 +
src/bin/pg_combinebackup/t/013_summary_order.pl | 94 +++++++++++++++++++++++++
3 files changed, 114 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-11-01 15:27:22 pgsql: Fix incremental backup data loss due to WAL summary merge order
Previous Message Fujii Masao 2026-11-01 15:26:58 pgsql: Fix incremental backup data loss due to WAL summary merge order