]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Prevent restore of incremental backup from bloating VM fork.
authorRobert Haas <rhaas@postgresql.org>
Mon, 9 Mar 2026 10:36:42 +0000 (06:36 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 9 Mar 2026 10:46:20 +0000 (06:46 -0400)
commit9540c0e5dd40df47cbea9a596975e6688ccd70a3
tree4e23d355608379a20ea43ab54e1d65cc6825867c
parent94ff80f49d64ed3b2b5fe598732600c9bb1beb71
Prevent restore of incremental backup from bloating VM fork.

When I (rhaas) wrote the WAL summarizer code, I incorrectly believed
that XLOG_SMGR_TRUNCATE truncates all forks to the same length.  In
fact, what other parts of the code do is compute the truncation length
for the FSM and VM forks from the truncation length used for the main
fork. But, because I was confused, I coded the WAL summarizer to set the
limit block for the VM fork to the same value as for the main fork.
(Incremental backup always copies FSM forks in full, so there is no
similar issue in that case.)

Doing that doesn't directly cause any data corruption, as far as I can
see. However, it does create a serious risk of consuming a large amount
of extra disk space, because pg_combinebackup's reconstruct.c believes
that the reconstructed file should always be at least as long as the
limit block value. We might want to be smarter about that at some point
in the future, because it's always safe to omit all-zeroes blocks at the
end of the last segment of a relation, and doing so could save disk
space, but the current algorithm will rarely waste enough disk space to
worry about unless we believe that a relation has been truncated to a
length much longer than its actual length on disk, which is exactly what
happens as a result of the problem mentioned in the previous paragraph.

To fix, create a new visibilitymap helper function and use it to include
the right limit block in the summary files. Incremental backups taken
with existing summary files will still have this issue, but this should
improve the situation going forward.

Diagnosed-by: Oleg Tkachenko <oatkachenko@gmail.com>
Diagnosed-by: Amul Sul <sulamul@gmail.com>
Discussion: http://postgr.es/m/CAAJ_b97PqG89hvPNJ8cGwmk94gJ9KOf_pLsowUyQGZgJY32o9g@mail.gmail.com
Discussion: http://postgr.es/m/6897DAF7-B699-41BF-A6FB-B818FCFFD585%40gmail.com
Backpatch-through: 17
src/backend/access/heap/visibilitymap.c
src/backend/postmaster/walsummarizer.c
src/bin/pg_combinebackup/t/011_ib_truncation.pl
src/include/access/visibilitymap.h