Incremental backup can use a summary past a timeline switch
Incremental backup can use a summary past a timeline switch
Hi,
Moving the corner case I mentioned in the BUG #19774 thread [1] here,
as Fujii-san suggested.
IIUC, a standby can summarize WAL ahead of replay. So if recovery
ends at the start of one of those summaries, we could still have an
old-timeline summary for WAL we didn't replay. FilterWalSummaries()
seems to keep that file, unlike GetWalSummaries().
My worry was that a truncation in that summary could drop block
references from the new timeline when we merge it. We'd then miss
those blocks in the incremental backup and take stale ones from the
earlier backup instead.
The attached patch makes the >= / <= checks match GetWalSummaries().
I have a TAP reproducer, but it's fairly involved, so I've kept it out
of the patch for now. Happy to share it if it's useful.
[1] https://postgr.es/m/19774-8a1cbfd1774fcd0c@postgresql.org
Regards,
Ayush
Moving the corner case I mentioned in the BUG #19774 thread [1] here,
as Fujii-san suggested.
IIUC, a standby can summarize WAL ahead of replay. So if recovery
ends at the start of one of those summaries, we could still have an
old-timeline summary for WAL we didn't replay. FilterWalSummaries()
seems to keep that file, unlike GetWalSummaries().
My worry was that a truncation in that summary could drop block
references from the new timeline when we merge it. We'd then miss
those blocks in the incremental backup and take stale ones from the
earlier backup instead.
The attached patch makes the >= / <= checks match GetWalSummaries().
I have a TAP reproducer, but it's fairly involved, so I've kept it out
of the patch for now. Happy to share it if it's useful.
[1] https://postgr.es/m/19774-8a1cbfd1774fcd0c@postgresql.org
Regards,
Ayush
Re: Incremental backup can use a summary past a timeline switch
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Oct 23, 2026, at 01:59, Ayush Tiwari wrote: > > Hi, > > Moving the corner case I mentioned in the BUG #19774 thread [1] here, > as Fujii-san suggested. > > IIUC, a standby can summarize WAL ahead of replay. So if recovery > ends at the start of one of those summaries, we could still have an > old-timeline summary for WAL we didn't replay. FilterWalSummaries() > seems to keep that file, unlike GetWalSummaries(). > > My worry was that a truncation in that summary could drop block > references from the new timeline when we merge it. We'd then miss > those blocks in the incremental backup and take stale ones from the > earlier backup instead. > > The attached patch makes the >= / <= checks match GetWalSummaries(). > > I have a TAP reproducer, but it's fairly involved, so I've kept it out > of the patch for now. Happy to share it if it's useful. > > [1] https://postgr.es/m/19774-8a1cbfd1774fcd0c@postgresql.org > > Regards, > Ayush > I think the fix is correct. FilterWalSummaries()’s header comment already correctly describes the behavior with “after” and “before”, but the code was wrong. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
Re: Incremental backup can use a summary past a timeline switch
Hi Ayush, On Thu, Oct 22, 2026 at 11:29 PM Ayush Tiwari wrote: > My worry was that a truncation in that summary could drop block > references from the new timeline when we merge it. We'd then miss > those blocks in the incremental backup and take stale ones from the > earlier backup instead. I could reproduce it. The setup is in the attached script: the standby pauses at recovery_target_lsn = the redo LSN of a checkpoint, with recovery_target_inclusive = false. Before that point the primary updates rows 5..8 of an 8-block table, which the standby replays. After it, the primary runs DELETE + VACUUM, truncating the table to 4 blocks, and checkpoints. The standby summarizes that WAL but never replays it, and is then promoted. The timeline 1 summary that starts at the switch point holds "limit 4" for the table. It gets merged and drops blocks 4..11, the INCREMENTAL file ends up with 0 blocks and truncation_block_length 12, and after pg_combinebackup rows 5..8 come back with their pre-update contents. pg_verifybackup reports both backups as valid. On master with Fujii's v1-0001 from the #19774 thread that happened in 5 of 5 runs on tmpfs and 5 of 5 on btrfs. Without v1-0001 it was 5 of 5 on btrfs and 0 of 5 on tmpfs, where readdir happens to merge the old-timeline summary first. With your v1: 0 of 10, with and without v1-0001. Your patch applies cleanly either way, and make check, pg_walsummary, pg_combinebackup and the recovery suite pass with it. One note for anyone running the script: reading the table on the promoted server before the backup can hide the loss, because with data checksums the hint-bit FPIs mark those blocks again on the new timeline. The script also keeps the target off page boundaries, which hit a different error [1]. [1] https://postgr.es/m/CAK49S1A28oFELOo++Vo2Nr_Jh0KQcv5GwUs7dXNLDW7qLiZiXw@mail.gmail.com Regards, Manu
Re: Incremental backup can use a summary past a timeline switch
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Sat, Oct 24, 2026 at 4:43 AM Manu wrote: > Without v1-0001 it was 5 of > 5 on btrfs and 0 of 5 on tmpfs, where readdir happens to merge the > old-timeline summary first. Thanks for testing! The patch looks good to me. I'm thinking to commit this before the fix for [1], since changing the merge order could expose the bug in cases where it was previously hidden. Barring any objections, I'll commit this patch first. For v20, we could also consider sharing the filtering logic between GetWalSummaries() and FilterWalSummaries() to avoid similar inconsistencies. Regards, [1] https://postgr.es/m/19774-8a1cbfd1774fcd0c@postgresql.org -- Fujii Masao
Re: Incremental backup can use a summary past a timeline switch
От:
shihao zhong <zhong950419@gmail.com>
Дата:
Hi Fujii,
+1 to commit this patch first.
It does not cover one more case. If the recovery target is not at a
checkpoint redo, a timeline 1 summary can go past the switch point,
and a truncation after that point still drops blocks. This is the
case from the "Assertion failure in WAL summarizer" thread [1], and
Manu's 0002 there fixes it on top of this patch.
[1] https://postgr.es/m/179296590548.3326877.13182798945037392623@gmail.com
Thanks,
Shihao
+1 to commit this patch first.
It does not cover one more case. If the recovery target is not at a
checkpoint redo, a timeline 1 summary can go past the switch point,
and a truncation after that point still drops blocks. This is the
case from the "Assertion failure in WAL summarizer" thread [1], and
Manu's 0002 there fixes it on top of this patch.
[1] https://postgr.es/m/179296590548.3326877.13182798945037392623@gmail.com
Thanks,
Shihao
Re: Incremental backup can use a summary past a timeline switch
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Sun, Nov 1, 2026 at 9:56 AM shihao zhong wrote: > +1 to commit this patch first. I've pushed the patch. Thanks! > It does not cover one more case. If the recovery target is not at a > checkpoint redo, a timeline 1 summary can go past the switch point, > and a truncation after that point still drops blocks. This is the > case from the "Assertion failure in WAL summarizer" thread [1], and > Manu's 0002 there fixes it on top of this patch. > > [1] https://postgr.es/m/179296590548.3326877.13182798945037392623@gmail.com Yes, I'm planning to work on that. Regards, -- Fujii Masao