Re: Incremental backup inconsistency after vacuum truncation + COPY regrowth

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Cc: Boyu Yang <pgsql(at)mail-yby(dot)icu>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: Incremental backup inconsistency after vacuum truncation + COPY regrowth
Date: 2026-12-05 18:06:30
Message-ID: CAPHduZDiaDA2BiKL2E5Hbw-27KjCq2v2DSn8Ogsdms=3YLyokw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Dec 2, 2026 at 4:30 PM Zhijie Hou wrote:
> Rather than backing up the entire affected segment, I am thinking shall
> change the following comparison to '>' so that *truncation_block_length
> is clamped to relative_limit, matching the comment

I reviewed v1 and tested it on master a069c99680 (macOS, meson,
cassert). Master already has 4280abf884, which fixed the pg_combinebackup
side for intermediate truncations. Boyu's case still fails there with a
single incremental, so this is a separate bug in GetFileBackupMethod().

Boyu's POC (40 rows, VACUUM truncation to 1 block, COPY of 20 rows,
full + incremental, combine):
master: primary 21 rows, combined 33 rows (ids 22-33 come back);
the incremental header has truncation_block_length 33
v1: combined 21 rows, md5 of the table equals the primary's;
header has truncation_block_length 1, blocks 1-20 and 32
Also with v1: truncation to 0 blocks (whole file is sent, result
correct), and a chain full -> incr1 -> incr2 (result correct).

Tests:
- With v1: pg_combinebackup + pg_walsummary suites 17/17 pass,
pg_basebackup + pg_verifybackup 16/16 pass. With -Dsegsize_blocks=6
(one of the CI configurations): pg_combinebackup + pg_walsummary 17/17.
- New 011 test, server code reverted to master: "not ok 8" (got '4|1',
expected '3|0').
- Keeping the clamp but dropping the last-block hunk: "not ok 9" (got
'3', expected '4').
- pgindent --check on basebackup_incremental.c: clean.
- git apply --check: clean on master, REL_18_STABLE and REL_17_STABLE
(only line offsets). I did not build or test the back branches.

About the last-block hunk: the new comment says it keeps the file
length, but it does not say why that matters. The case where it matters
is when the segment that holds limit_block is not the last segment.
I checked this on a segsize_blocks=6 build. Truncate to 22 blocks, so
limit_block is in segment 3. Blocks 22-23 are zero-filled and have no
WAL. I made them by appending zero pages with the server stopped, the
same bytes mdzeroextend() writes. Then one row goes into block 24, in
segment 4. Results:
master: combined 25 rows (ids 23 and 24 come back)
v1: combined 23 rows, same as the primary
v1 without that hunk: combined 22 rows. The row in block 24 is lost,
because segment 3 is rebuilt with 4 blocks and
segment 4 is no longer read.
So in this layout the hunk prevents data loss, not just a length
difference. A sentence about it in the comment would help the next
reader.

Minor points:
- The new part of 011 depends on COPY extending the relation by an
extra block. With the TAP default shared_buffers (128 buffers), the
precondition fails: "not ok 6", got '3'. With 1024, 2048, 16384 and
131072 it passes. The test sets 2048, so it is fine as written, and if
the extension behaviour changes, test 6 fails instead of silently
passing. It is the same kind of COPY dependency that Fujii called
fragile in the BUG #19776 thread.
- The RELSEG_SIZE cap from ecd275718be can no longer be reached
(truncation_block_length now starts at size / BLCKSZ, which is already
checked against RELSEG_SIZE at the top, and can only go down). It may
be worth keeping it as an Assert.

Not tested: the VM fork, timeline switches, the size < relative_limit
path (relation truncated after the backup started; v1 now uses the
file's size there instead of raising to relative_limit), Boyu's
alternative patch, and perltidy on the .pl file.

Regards,
Raja Sai Pranav

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kacper Kuras 2026-12-05 18:16:56 Re: Proposal: INSERT ... BY NAME
Previous Message Tomas Vondra 2026-12-05 18:02:53 Re: Making type Datum be 8 bytes everywhere