Assertion failure in WAL summarizer
Hi,
While working on [1]/messages/by-id/19774-8a1cbfd1774fcd0c@postgresql.org, I encountered the following assertion failure in
the WAL summarizer:
TRAP: failed Assert("end_of_summary_lsn >= current_lsn"), File:
"walsummarizer.c", Line: 460, PID: 37935
I haven't investigated this yet, but wanted to report it in advance.
The following steps reproduce the failure:
-------------------------------------------------------
initdb -D data
echo "summarize_wal = on" >> data/postgresql.conf
pg_ctl -D data start
psql -c "CREATE TABLE t (i int)"
pg_basebackup -D sby -c fast -R
psql -c "INSERT INTO t VALUES (1)"
psql -c "CHECKPOINT"
psql -c "SELECT redo_lsn FROM pg_control_checkpoint()" # Save this redo_lsn
psql -c "INSERT INTO t VALUES (2)"
psql -c "CHECKPOINT"
cat << EOF >> sby/postgresql.conf
port = 5433
recovery_target_lsn = '0/03001B08' # Use the saved redo_lsn
recovery_target_inclusive = false
recovery_target_action = 'pause'
EOF
pg_ctl -D sby start
# Wait until all three queries return true
psql -c "SELECT pg_get_wal_replay_pause_state() = 'paused'" -p 5433
psql -c "SELECT EXISTS (SELECT FROM pg_available_wal_summaries() WHERE
tli = 1 AND start_lsn = '0/03001B08')" -p 5433 # Use the saved
redo_lsn
psql -c "SELECT EXISTS (SELECT FROM pg_stat_activity WHERE
backend_type = 'walsummarizer' AND wait_event = 'WalSummarizerWal')"
-p 5433
pg_ctl -D sby promote
-------------------------------------------------------
After promotion, I got the following messages:
-------------------------------------------------------
\
2026-10-22 10:01:53.329 JST [37932] LOG: selected new timeline ID: 2
2026-10-22 10:01:53.361 JST [37932] LOG: archive recovery complete
TRAP: failed Assert("end_of_summary_lsn >= current_lsn"), File:
"walsummarizer.c", Line: 460, PID: 37935
2026-10-22 10:01:53.363 JST [37930] LOG: checkpoint starting: force
2026-10-22 10:01:53.364 JST [37927] LOG: database system is ready to
accept connections
0 postgres 0x000000011060e742
ExceptionalCondition + 178
1 postgres 0x00000001102e9762
WalSummarizerMain + 1698
2 postgres 0x00000001102de549
postmaster_child_launch + 377
3 postgres 0x00000001102e2c91
StartChildProcess + 273
4 postgres 0x00000001102e4ec2
LaunchMissingBackgroundProcesses + 674
5 postgres 0x00000001102e30f9 ServerLoop + 489
6 postgres 0x00000001102e1e69 PostmasterMain + 5753
7 postgres 0x0000000110179e43 main + 771
8 dyld 0x00007ff811152530 start + 3056
2026-10-22 10:01:53.371 JST [37927] LOG: WAL summarizer process (PID
37935) was terminated by signal 6: Abort trap: 6
2026-10-22 10:01:53.371 JST [37927] LOG: terminating any other active
server processes
-------------------------------------------------------
Regards,
[1]: /messages/by-id/19774-8a1cbfd1774fcd0c@postgresql.org
--
Fujii Masao
Hi Fujii,
On Thu, Oct 22, 2026 at 10:38 AM Fujii Masao <masao.fujii@gmail.com> wrote:
I haven't investigated this yet, but wanted to report it in advance.
I can reproduce it with your steps on master, every time once the
three conditions hold, and also on REL_19, REL_18 and REL_17 with
cassert, so it goes back to when the summarizer was added.
Before promotion the summarizer has already gone past the recovery
target. In recovery GetLatestLSN() returns the walreceiver flush
position, and the walreceiver keeps streaming after replay pauses.
With your steps on master, replay pauses at the recovery target
0/03001B08, the walreceiver has flushed to 0/03001D98, and the
summarizer has summarized up to 0/03001CB0 and is waiting for WAL at
0/03001D98.
After promotion TLI 1 ends at 0/03001B08 ("1 0/03001B08 before LSN
0/03001B08" in 00000002.history), behind the summarizer. With gdb
attached to the summarizer:
1. summarizer_read_local_xlog_page() notices TLI 2 while waiting and
sets read_upto = switchpoint: 0/03001D98 -> 0/03001B08. The comment
there expects this ("this will cause read_upto to move backwards,
because we might have been promoted before reaching the end of the
previous timeline").
2. The next read is past read_upto on a timeline that is now historic,
so end_of_wal is set and SummarizeWAL() returns
summary_end_lsn = private_data->read_upto = 0/03001B08, although it
started at 0/03001CB0.
3. WalSummarizerMain(): current_lsn = 0/03001CB0,
end_of_summary_lsn = 0/03001B08 -> the assertion at line 460.
The main loop already handles "we passed the switch point": at the top
of the loop, if current_lsn >= switch_lsn it backs up to the switch
point on the new timeline. But that path only runs when the timeline
change is seen there. When it is seen inside SummarizeWAL(), the
backwards LSN comes back as the return value instead.
Without assertions nothing bad seems to happen. On a non-cassert build
of master with the same steps, the summarizer takes 0/03001B08 as its
position, sees TLI 2 on the next iteration, switches at 0/03001B08 and
goes on. It is the same process, and you end up with the same
summaries and state as with the patch below. So as far as I can tell
this only affects assert-enabled builds, but there the summarizer
crash makes the postmaster restart the whole cluster right after the
promotion.
The attached patch makes SummarizeWAL() report no progress when
read_upto ended up before the start of the summary, so the existing
code in the main loop does the rewind on the next iteration. With it,
your steps no longer trip the assertion, and summarization resumes on
TLI 2 exactly at the target, on master, 19, 18 and 17 (the patch
applies to all four). It also adds
src/bin/pg_walsummary/t/004_promote_past_target.pl, which follows your
steps: it fails with the TRAP on unpatched master and passes with the
fix. make check, pg_walsummary and pg_combinebackup pass.
Another option is to relax the assertion and keep the current
behavior, since that is already what a non-assert build does. I went
with the clamp because then SummarizeWAL() never returns an LSN before
its start, and summarized_lsn doesn't go backwards on the old timeline
for an iteration before the rewind. No strong opinion, though.
Regards,
Manu
Hi,
I hit the same assertion independently earlier and can confirm Manu's
analysis.
Before promotion, with Fujii's steps on master:
replay 0/03001B08
receive 0/03001D98
summarized 0/03001CB0
which matches the numbers in Manu's mail. The size of the gap between
replay and receive doesn't matter: with ~20MB of streamed WAL past an
arbitrary recovery_target_lsn (recovery_target_inclusive = true) the
summarizer is ~20MB ahead and the crash is the same.
With cassert disabled, I don't see any adverse effects either: summaries
on TLI 2 start at the switch point, and an incremental backup across the
promotion works.
With v1 applied on master, the same scenarios pass with cassert and the
new test passes; with the walsummarizer.c hunk reverted, the test fails
with the TRAP. pg_walsummary and pg_combinebackup TAP suites pass.
A couple of minor comments on v1:
1. The comment in summarizer_read_local_xlog_page() about read_upto
moving backwards says the next iteration will "likely conclude that
we've reached end of WAL". It might be worth mentioning there that
SummarizeWAL() then reports no progress, so the link between the two
places is visible from both sides.
2. In the test, the summarizer PID check and the log check both detect
the same thing, a restart after the crash. Without the fix neither
is reached anyway: pg_ctl promote fails once the postmaster
reinitializes, and the test dies without a plan. I think one of the
two checks would be sufficient.
Separately, while looking at this I found a related but different
problem: if the switch point falls exactly on a page or segment
boundary, the first summary on the new timeline starts after the page
header, and incremental backups on top of any pre-promotion backup fail
permanently with "WAL summaries are required on timeline 2 from
0/04000000 ...". v1 doesn't change that, and it isn't expected to. I'll
look into it
more closely and then maybe start a separate thread with a reproducer.
--
Daria Lepikhova
Hi Daria,
Thanks for confirming the analysis independently, and for the review
and testing.
On Thu, Oct 22, 2026 at 10:30 AM Daria Lepikhova
<daria.n.lepikhova@gmail.com> wrote:
1. The comment in summarizer_read_local_xlog_page() about read_upto
moving backwards says the next iteration will "likely conclude that
we've reached end of WAL". It might be worth mentioning there that
SummarizeWAL() then reports no progress, so the link between the two
places is visible from both sides.
Done in the attached v2. The comment now ends with "If the switch
point precedes the start of the current summary, SummarizeWAL() then
reports no progress." The comment on the clamp in SummarizeWAL()
already points back to summarizer_read_local_xlog_page().
2. In the test, the summarizer PID check and the log check both detect
the same thing, a restart after the crash. Without the fix neither
is reached anyway: pg_ctl promote fails once the postmaster
reinitializes, and the test dies without a plan. I think one of the
two checks would be sufficient.
Agreed. v2 keeps only the log check, since log_contains() doesn't need
a running server.
TAP nodes run with restart_after_crash = off, so the crash shuts the
standby down instead of reinitializing it, 73-105 ms after it reaches
production in my runs. pg_ctl promote polls every 100 ms, so whether
it sees the promotion first is a race. Here promote won in 13 of 13
runs without the fix, and the v1 test then failed "not ok 1" and died
on the PID query against the stopped server. With v2 and the fix
reverted, it now ends with "failed 2 tests of 2" instead (4 of 4).
When promote loses the race, as in your run, the test still bails out
at promote. I left that as it is.
v2 applies to master, 19, 18 and 17 like v1, and passes there.
Separately, while looking at this I found a related but different
problem: if the switch point falls exactly on a page or segment
boundary, [...]
Looking forward to that thread. I'm happy to run your reproducer
against v2 once you post it.
Regards,
Manu
Hi,
I think the same root cause can lose data in an incremental backup.
The standby summarizes WAL past the recovery target. If that WAL
truncates a table, the next incremental backup on the promoted server
skips blocks that changed before the target. The restored copy has old
data and no error.
The attached test have a repro.
In my test it goes away if GetLatestLSN() returns the replay position
during recovery. What do you think?
Thanks,
Shihao
Attachments:
noncfbot-test.txttext/plain; charset=US-ASCII; name=noncfbot-test.txtDownload+83-0
Hi Shihao,
On Sat, Oct 24, 2026 at 1:04 AM shihao zhong <zhong950419@gmail.com>
wrote:
In my test it goes away if GetLatestLSN() returns the replay position
during recovery. What do you think?
I think you're right. Your test fails on master in 3 of 3 runs (the
restored copy has 4|0 instead of 4|1) and passes with the attached
0002, which is your idea: during recovery GetLatestLSN() returns the
replay position instead of the walreceiver's flush position
(walsummarizer.c:879-890 on master), so no summary of the old timeline
goes past the switch point. I'll add you as Reported-by to 0002 in
the next version.
0002 also takes away what Fujii's assertion needs, a summarizer ahead
of replay at promotion. On a cassert build of the series without my
v2 fix from upthread, the standby never summarizes past the recovery
target, and the 004 test from v2 times out in its setup waiting for
such a summary (3 of 3). So with 0002 in, v2's change would only be
defensive and its test would need a different setup; without 0002,
v2 is still needed.
0002 does not help with a summary that is already on disk, so 0001
covers that. In repro-C-upgrade.sh.txt the standby runs master until
the promotion and writes a timeline 1 summary across the switch point;
then the server is restarted on the full series (the two patches
below plus 0001 and 0002). The summary is still there, and 0001
refuses the backup (3 of 3) because it records a truncation; summary
entries carry no LSNs, so the part past the switch can't be dropped.
Restarted on master instead, the restore loses data (3 of 3). I did
not build 0002 alone; its backup path is master's.
Two neighboring cases came up this week: Ayush's summary that starts
exactly at the switch point [1]/messages/by-id/CAJTYsWV7RThdo4K62G8hC=Anpkbr54QWbOvyVvw5uvx4+-x_DQ@mail.gmail.com, and Sai Pranav's prior backup that
ends past it [2]/messages/by-id/CAPHduZC9pWm_vjznmhZNFsDZKLimqc6dKXOozLUKZVPs19zbZg@mail.gmail.com. 0001 goes on top of their patches as posted and adds
only the check for this case; with both of theirs and none of ours,
your case still loses (measurements.txt, table 1).
Robert, the open question is 0002. The flush branch dates from the
first commit, and I could not find why flushed rather than replayed;
in the original thread you called what summarization should do during
recovery "very much live" [3]/messages/by-id/CA+Tgmoad7igbt46K+JHG6UEZ56Y5SVBYq5e7OjcKkgD3SStNmg@mail.gmail.com. Is anything relying on standby
summaries ahead of replay? If so, 0001 alone covers this by refusing.
Your test name collides with Ayush's t/014; I ran it as t/016.
[1]: /messages/by-id/CAJTYsWV7RThdo4K62G8hC=Anpkbr54QWbOvyVvw5uvx4+-x_DQ@mail.gmail.com
[2]: /messages/by-id/CAPHduZC9pWm_vjznmhZNFsDZKLimqc6dKXOozLUKZVPs19zbZg@mail.gmail.com
[3]: /messages/by-id/CA+Tgmoad7igbt46K+JHG6UEZ56Y5SVBYq5e7OjcKkgD3SStNmg@mail.gmail.com
Regards,
Manu
Hi Manu,
I tried the series (v2-0001 from upthread plus your v1-0001 and v1-0002) on
current master. The code applies unchanged; only the pg_combinebackup
meson.build hunk conflicts now that 013_summary_order is in, so I added 014
and 015 to the test list by hand.
Linux aarch64, --enable-cassert --enable-debug --enable-tap-tests:
- pg_combinebackup and pg_basebackup pass.
- 014, 015 and Shihao's test (run as 016) pass 3 of 3 with the series. With
the same tree but master's walsummarizer.c and basebackup_incremental.c,
all three fail 3 of 3. On this cassert build Shihao's test fails earlier
than in his report: the summarizer hits Assert("end_of_summary_lsn >=
current_lsn") after promotion, so the backup fails before the data can be
checked.
- pg_walsummary's 004_promote_past_target times out in its setup with 0002
applied, as you said: the standby never summarizes past the target. So the
v2 test needs a different setup if 0002 goes in.
Regards,
Sai Pranav
On Mon, Oct 26, 2026 03:35 AM, Manu <manuelreyesbravo@gmail.com> wrote:
Show quoted text
Hi Shihao,
On Sat, Oct 24, 2026 at 1:04 AM shihao zhong <zhong950419@gmail.com>
wrote:In my test it goes away if GetLatestLSN() returns the replay position
during recovery. What do you think?I think you're right. Your test fails on master in 3 of 3 runs (the
restored copy has 4|0 instead of 4|1) and passes with the attached
0002, which is your idea: during recovery GetLatestLSN() returns the
replay position instead of the walreceiver's flush position
(walsummarizer.c:879-890 on master), so no summary of the old timeline
goes past the switch point. I'll add you as Reported-by to 0002 in
the next version.0002 also takes away what Fujii's assertion needs, a summarizer ahead
of replay at promotion. On a cassert build of the series without my
v2 fix from upthread, the standby never summarizes past the recovery
target, and the 004 test from v2 times out in its setup waiting for
such a summary (3 of 3). So with 0002 in, v2's change would only be
defensive and its test would need a different setup; without 0002,
v2 is still needed.0002 does not help with a summary that is already on disk, so 0001
covers that. In repro-C-upgrade.sh.txt the standby runs master until
the promotion and writes a timeline 1 summary across the switch point;
then the server is restarted on the full series (the two patches
below plus 0001 and 0002). The summary is still there, and 0001
refuses the backup (3 of 3) because it records a truncation; summary
entries carry no LSNs, so the part past the switch can't be dropped.
Restarted on master instead, the restore loses data (3 of 3). I did
not build 0002 alone; its backup path is master's.Two neighboring cases came up this week: Ayush's summary that starts
exactly at the switch point [1], and Sai Pranav's prior backup that
ends past it [2]. 0001 goes on top of their patches as posted and adds
only the check for this case; with both of theirs and none of ours,
your case still loses (measurements.txt, table 1).Robert, the open question is 0002. The flush branch dates from the
first commit, and I could not find why flushed rather than replayed;
in the original thread you called what summarization should do during
recovery "very much live" [3]. Is anything relying on standby
summaries ahead of replay? If so, 0001 alone covers this by refusing.Your test name collides with Ayush's t/014; I ran it as t/016.
[1] /messages/by-id/CAJTYsWV7RThdo4K62G8hC=Anpkbr54QWbOvyVvw
5uvx4+-x_DQ@mail.gmail.com
[2] /messages/by-id/CAPHduZC9pWm_vjznmhZNFsDZKLimqc6dKXOozLU
KZVPs19zbZg@mail.gmail.com
[3] /messages/by-id/CA+Tgmoad7igbt46K+JHG6UEZ56Y5SVBYq5e7Ojc
KkgD3SStNmg@mail.gmail.comRegards,
Manu
Hi Sai Pranav,
On Mon, Nov 2, 2026 at 11:56 PM Raja Sai pranav
<rajasaipranav0@gmail.com> wrote:
I tried the series (v2-0001 from upthread plus your v1-0001 and v1-0002) on
current master.
Thanks for testing it on aarch64. v3 is attached, rebased on
f549ecd2660 and 316861101e8; v1's t/014 is dropped, as f549ecd2660
covers that case.
- pg_walsummary's 004_promote_past_target times out in its setup with 0002
applied, as you said: the standby never summarizes past the target.
0001 keeps the v2 test, which trips the assertion on master. 0003
(formerly 0002) makes it promote while the summarizer waits at replay,
since the v2 check is then only defensive.
On today's master without cassert, Shihao's test (now t/015) still
restores 4|0 instead of 4|1, 3 of 3; with the series it passes 3 of 3.
0003 now lists Shihao as co-author, since the idea and t/015 are his.
Fujii, v3 is on top of what you committed, in case it helps.
Robert, for 0003: does anything rely on summaries ahead of replay?
Regards,
Manu
On Tue, Nov 3, 2026 at 8:29 AM Manu <manuelreyesbravo@gmail.com> wrote:
Robert, for 0003: does anything rely on summaries ahead of replay?
I don't believe so. I just didn't realize that we needed to limit
summarization to the replay LSN.
--
Robert Haas
Databricks
Hi,
v3 no longer applies on master. I did not see any new comments.
So v4 is just a rebase.
Thanks,
Attachments:
t254307_10v4-0002-Refuse-truncations-from-WAL-summaries-that-cross-a-t.patchapplication/octet-stream; name=v4-0002-Refuse-truncations-from-WAL-summaries-that-cross-a-t.patchDownload+173-2
v4-0001-Fix-assertion-failure-in-WAL-summarizer-after-promot.patchapplication/octet-stream; name=v4-0001-Fix-assertion-failure-in-WAL-summarizer-after-promot.patchDownload+94-2
v4-0003-Summarize-only-replayed-WAL-on-a-standby.patchapplication/octet-stream; name=v4-0003-Summarize-only-replayed-WAL-on-a-standby.patchDownload+172-66
Hi,
I re-tested the v4 series on current master (76c0df7).
- All three patches apply cleanly with `git am` (0001, 0002, 0003).
- Builds with --enable-cassert --enable-debug --enable-tap-tests, no new
warnings.
- Both affected TAP suites are green on an assert-enabled build:
- pg_combinebackup: Files=16, Tests=147, Result: PASS
(new t/
https://www.google.com/url?q=http://015_summary_past_switch.pl&source=gmail&ust=1794453437308000&sa=E
and t/
https://www.google.com/url?q=http://016_truncation_after_target.pl&source=gmail&ust=1794453437308000&sa=E
both ok)
- pg_walsummary: Files=4, Tests=34, Result: PASS
(new t/
https://www.google.com/url?q=http://004_promote_past_target.pl&source=gmail&ust=1794453437308000&sa=E
ok)
Since this is a cassert build, t/
https://www.google.com/url?q=http://004_promote_past_target.pl&source=gmail&ust=1794453437308000&sa=E
and
t/
https://www.google.com/url?q=http://015_summary_past_switch.pl&source=gmail&ust=1794453437308000&sa=E
exercising the promote/timeline-switch paths
without tripping an assertion is the result we want.
As you say, v4 is a straight rebase of v3 with no code changes, so this just
confirms it still applies and passes cleanly on today's master. LGTM from my
side.
Regards,
Sai Pranav
On Wed, Nov 11, 2026 08:04 AM, shihao zhong <zhong950419@gmail.com> wrote:
Show quoted text
Hi,
v3 no longer applies on master. I did not see any new comments.
So v4 is just a rebase.
Thanks,
Hi,
Beyond confirming v4 applies and the suites pass, I checked that each new
test
actually reproduces its failure on unpatched master -- i.e. with the three
test
files in place but the code changes reverted:
- pg_walsummary/t/
https://www.google.com/url?q=http://004_promote_past_target.pl&source=gmail&ust=1794456004508000&sa=E:
fails at "the summarizer does not
read past replay", and pg_ctl promote then exits 1 -- the post-promotion
path
this series fixes.
- pg_combinebackup/t/
https://www.google.com/url?q=http://015_summary_past_switch.pl&source=gmail&ust=1794456004508000&sa=E:
the same "reads past replay"
failure on the standby, and promote exits 1.
- pg_combinebackup/t/
https://www.google.com/url?q=http://016_truncation_after_target.pl&source=gmail&ust=1794456004508000&sa=E:
the server terminates
abnormally during the post-promotion incremental backup
(pg_basebackup: server closed the connection unexpectedly).
With all three patches applied, every test passes (pg_combinebackup 147/147,
pg_walsummary 34/34, on an assert-enabled build). So the tests reproduce the
reported failures -- including the server crash on the
truncation-after-target
path -- and the series resolves them.
Regards,
Sai Pranav
On Wed, Nov 11, 2026 08:04 AM, shihao zhong <zhong950419@gmail.com> wrote:
Show quoted text
Hi,
v3 no longer applies on master. I did not see any new comments.
So v4 is just a rebase.
Thanks,
Hi Shihao and Sai,
On Tue, Nov 10, 2026 at 8:00 PM Raja Sai pranav
<rajasaipranav0@gmail.com> wrote:
With all three patches applied, every test passes (pg_combinebackup
147/147, pg_walsummary 34/34, on an assert-enabled build).
Thanks, Shihao, for the rebase, and Sai for the two rounds of testing.
I got the same on master as of 952bab8b74d, and I also built it with
meson and clang, as CFbot does: no warnings, and the 23 tests of
pg_walsummary and pg_combinebackup pass. pgindent changes nothing.
One small thing: the commit message of 0003 still names
t/014_summary_past_switch.pl and t/015_truncation_after_target.pl.
Since b5545d3f5f9 took t/014 in pg_combinebackup, they are now
t/015_summary_past_switch.pl and t/016_truncation_after_target.pl.
Regards,
Manu
Hi,
Following up now that master has moved on a bit (currently 9a84976): the
v4 series still rebases cleanly and all three tests pass under
--enable-cassert --enable-tap-tests (004_promote_past_target,
015_summary_past_switch, 016_truncation_after_target).
While re-reading 0002 I wanted to double-check the limit_block == 0
exclusion in the cross-timeline truncation guard, since truncating an
existing relation to zero records limit_block = 0 just like a fork
creation does. It looks correct to me: a limit_block of 0 takes the
limit_block <= segno * RELSEG_SIZE path in GetFileBackupMethod() and
returns BACK_UP_FILE_FULLY, so the whole current file is sent as-is and
no stale truncation is applied. Only a limit_block > 0 from a past-switch
summary can discard block references, which is exactly what the guard
refuses. I also confirmed this end to end: truncating a table to zero,
re-inserting different rows, then taking an incremental backup and running
pg_combinebackup reconstructs a cluster whose rows match the source
exactly.
Still Tested-by on the series.
Thanks,
Sai Pranav
On Wed, Nov 11, 2026 11:10 AM, Manu <manuelreyesbravo@gmail.com> wrote:
Show quoted text
Hi Shihao and Sai,
On Tue, Nov 10, 2026 at 8:00 PM Raja Sai pranav
<rajasaipranav0@gmail.com> wrote:With all three patches applied, every test passes (pg_combinebackup
147/147, pg_walsummary 34/34, on an assert-enabled build).Thanks, Shihao, for the rebase, and Sai for the two rounds of testing.
I got the same on master as of 952bab8b74d, and I also built it with
meson and clang, as CFbot does: no warnings, and the 23 tests of
pg_walsummary and pg_combinebackup pass. pgindent changes nothing.One small thing: the commit message of 0003 still names
t/014_summary_past_switch.pl and t/015_truncation_after_target.pl.
Since b5545d3f5f9 took t/014 in pg_combinebackup, they are now
t/015_summary_past_switch.pl and t/016_truncation_after_target.pl.Regards,
Manu
Hi folks,
Thanks for reviewing my patch.
V5 include commit message fix Manu pointed and comment
Also João's review went to a new thread[1]/messages/by-id/CADMs5OOiP7Cfnah6XWXZYEMbsNAJF2Cy+TOwjGPCa=pbxU4ATw@mail.gmail.com, so here is the link.
[1]: /messages/by-id/CADMs5OOiP7Cfnah6XWXZYEMbsNAJF2Cy+TOwjGPCa=pbxU4ATw@mail.gmail.com
/messages/by-id/CADMs5OOiP7Cfnah6XWXZYEMbsNAJF2Cy+TOwjGPCa=pbxU4ATw@mail.gmail.com
Thanks,
Shihao
Attachments:
t254307_15v5-0003-Summarize-only-replayed-WAL-on-a-standby.patchapplication/octet-stream; name=v5-0003-Summarize-only-replayed-WAL-on-a-standby.patchDownload+173-66
v5-0002-Refuse-truncations-from-WAL-summaries-that-cross-a-t.patchapplication/octet-stream; name=v5-0002-Refuse-truncations-from-WAL-summaries-that-cross-a-t.patchDownload+173-2
v5-0001-Fix-assertion-failure-in-WAL-summarizer-after-promot.patchapplication/octet-stream; name=v5-0001-Fix-assertion-failure-in-WAL-summarizer-after-promot.patchDownload+94-2
Hello
0002 misses an old summary that ends exactly at the switch point
The 0003 commit message says that a summary written before a minor update "can still be on disk ... and the check added by the previous commit still refuses it". That holds for a summary that crosses the switch point, but not when the old summarizer was in the middle of a summary at promotion time:
* It has already added the records past the target to its block reference table
* then summarizer_read_local_xlog_page() moves read_upto back to the switch point
* SummarizeWAL() hits end of WAL and writes the file as [start, switch point], with the truncation from past the target inside it
* ws->end_lsn == tli_end_lsn, so 0002 doesn't flag it
Reproduction steps:
primary: summarize_wal = on, autovacuum = off
CREATE TABLE t (id int, v int, pad text STORAGE PLAIN);
INSERT INTO t SELECT g, 0, repeat('x', 4096) FROM generate_series(1,4) g;
VACUUM t;
pg_basebackup -D full -c fast -R
UPDATE t SET v = 1 WHERE id = 4;
SELECT pg_current_wal_insert_lsn(); -- recovery_target_lsn for the standby
standby from the same backup: summarize_wal = on, recovery_target_action = 'pause', running the old summarizer
primary: DELETE FROM t WHERE id > 1; VACUUM t;
wait for the standby to pause and its summarizer to catch up with the received WAL
pg_ctl -m immediate stop the primary, promote the standby
restart the standby on 18 + v5, pg_basebackup --incremental=full/backup_manifest, pg_combinebackup
Result:
00000002.history: 1 0/030051F0 after LSN 0/03004168
timeline 1 summary: 0/02000028 - 0/030051F0, limit block 1 for t
restored rows: 1|0 2|0 3|0 4|0
promoted server rows: 1|0 2|0 3|0 4|1
Hi Zsolt,
I reproduced this independently: REL_18_STABLE at 2f613719fa, standby
running the unpatched summarizer, then restarted on 18 + v5. Same result as
yours: the timeline 1 summary is 0/02000028-0/030051F0 (the switch point),
the incremental backup and pg_combinebackup succeed, and the restored table
has 4|0 where the promoted server has 4|1.
As a control, I ran the same steps with v5 on the standby from the start.
The timeline 1 summary has exactly the same range, 0/02000028-0/030051F0,
and the restored table is correct (4|1). So a summary written by the old
summarizer and a correct one can't be told apart by their LSN range, which
means the end_lsn check in 0002 can't catch this case, and changing it to
= would also refuse correct summaries. The 0003 commit message should
probably not claim that 0002 covers summaries left on disk from before the
update.
Regards,
Sai Pranav
On Mon, Nov 16, 2026 02:53 AM, Zsolt Parragi <zsolt.parragi@percona.com>
wrote:
Show quoted text
Hello
0002 misses an old summary that ends exactly at the switch point
The 0003 commit message says that a summary written before a minor
update "can still be on disk ... and the check added by the previous
commit still refuses it". That holds for a summary that crosses the
switch point, but not when the old summarizer was in the middle of a
summary at promotion time:* It has already added the records past the target to its block reference
table
* then summarizer_read_local_xlog_page() moves read_upto back to the
switch point
* SummarizeWAL() hits end of WAL and writes the file as [start, switch
point], with the truncation from past the target inside it
* ws->end_lsn == tli_end_lsn, so 0002 doesn't flag itReproduction steps:
primary: summarize_wal = on, autovacuum = off
CREATE TABLE t (id int, v int, pad text STORAGE PLAIN);
INSERT INTO t SELECT g, 0, repeat('x', 4096) FROM generate_series(1,4) g;
VACUUM t;
pg_basebackup -D full -c fast -R
UPDATE t SET v = 1 WHERE id = 4;
SELECT pg_current_wal_insert_lsn(); -- recovery_target_lsn for the
standby
standby from the same backup: summarize_wal = on,
recovery_target_action = 'pause', running the old summarizer
primary: DELETE FROM t WHERE id > 1; VACUUM t;
wait for the standby to pause and its summarizer to catch up with the
received WAL
pg_ctl -m immediate stop the primary, promote the standby
restart the standby on 18 + v5, pg_basebackup
--incremental=full/backup_manifest, pg_combinebackupResult:
00000002.history: 1 0/030051F0 after LSN 0/03004168
timeline 1 summary: 0/02000028 - 0/030051F0, limit block 1 for t
restored rows: 1|0 2|0 3|0 4|0
promoted server rows: 1|0 2|0 3|0 4|1
Hi Zsolt and Raja,
Thanks for the review! I appreciate it!
In v6, 0002 also checks a summary that ends at the switch point. It
no longer raises an error. Instead it backs up any relation fork that
such a summary truncates in full. That only costs space in an
incremental backup whose prior backup is older than the promotion.
Thanks,
Shihao
Attachments:
t254307_18v6-0002-Don-t-apply-truncations-from-WAL-summaries-that-r.patchapplication/octet-stream; name=v6-0002-Don-t-apply-truncations-from-WAL-summaries-that-r.patchDownload+183-2
v6-0001-Fix-assertion-failure-in-WAL-summarizer-after-pro.patchapplication/octet-stream; name=v6-0001-Fix-assertion-failure-in-WAL-summarizer-after-pro.patchDownload+94-2
v6-0003-Summarize-only-replayed-WAL-on-a-standby.patchapplication/octet-stream; name=v6-0003-Summarize-only-replayed-WAL-on-a-standby.patchDownload+231-67
Hi Shihao,
I re-ran the reproduction from my earlier mail against v6 (REL_18_STABLE
4d6ff8a051 + v6-0001..0003): the standby runs the unpatched summarizer,
then the promoted server is restarted on 18 + v6.
The timeline 1 summary is the same as before (0/02000028-0/030051F0, ending
at the switch point 0/30051F0). The incremental backup and pg_combinebackup
succeed, and the restored table now matches the promoted server (1|0 2|0
3|0 4|1), where v5 gave 4|0.
With v6-0002's check changed back to `ws->end_lsn > tli_end_lsn`, the
restored table is stale again (4|0), so the `>=` is what fixes it. The
control case, with v6 binaries on the standby from the start, also restores
correctly.
I didn't run the new
https://www.google.com/url?q=http://015_summary_past_switch.pl&source=gmail&ust=1795093490688000&sa=E
in this build.
Thanks,
Sai Pranav
On Tue, Nov 17, 2026 07:07 AM, shihao zhong <zhong950419@gmail.com> wrote:
Show quoted text
Hi Zsolt and Raja,
Thanks for the review! I appreciate it!
In v6, 0002 also checks a summary that ends at the switch point. It
no longer raises an error. Instead it backs up any relation fork that
such a summary truncates in full. That only costs space in an
incremental backup whose prior backup is older than the promotion.Thanks,
Shihao