Re: pg_receivewal doesn't truncate compressed WAL files on restart

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_receivewal doesn't truncate compressed WAL files on restart
Date: 2026-12-06 04:40:36
Message-ID: CAPHduZCpmUNxBxp2Cy4U6pS34WUNY4fqp_ZJ6ocOA92GqTuDVQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Dec 4, 2026 at 9:37 AM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> I've pushed the patch. Thanks!

Hi,

I tested 307f3edfb7 after the fact, as I touched the same code for
BUG #19890 (e87b024bfb). macOS, meson, cassert, master 91d71a71cb.

Repro without editing any file: pg_receivewal --synchronous
--compress=lz4, 40000 single-row commits, kill it mid-segment (SIGKILL
or SIGINT), restart without --synchronous until the segment completes,
then start it once more.

- fix reverted, lz4: the completed segment keeps the old size (2312683
bytes), the next start fails with ERROR_frameType_unknown, lz4 -t
rc=34. Hit in 4 of 4 runs at 40000 commits (none at 4000), also
across a timeline switch.
- fix reverted, gzip: "incorrect uncompressed size -65536, skipping";
as a later .partial already exists, streaming starts past it and the
bad .gz stays in the directory (gzip -t: trailing garbage, rc=2).
- with the fix: segment rewritten at 1775506 (lz4) / 1224445 (gzip)
bytes, lz4 -t / gzip -t rc=0, next start OK. Same with a timeline
switch and when resuming at a segment boundary. Uncompressed segment
still matches the server copy (cmp rc=0).
- Without --synchronous I did not hit it (1 run).
- 0002 passes on master and fails with the fix reverted (not ok 39).
pg_basebackup TAP suite passes, pgindent clean.

e87b024bfb is not changed by this: trailing junk makes
LZ4F_decompress() fail in FindStreamingStart() before the
incomplete-frame check, before and after the fix.

One user-facing point: the fix does not repair a segment already
written by an older minor. The fixed pg_receivewal on such a directory
still stops with ERROR_frameType_unknown (rc=1) until that segment is
removed. Maybe worth a line in the release notes?

Not tested: builds/runs on REL_15 to REL_18 (the 16-18 commits have the
same patch-id as v1, the REL_15 one I only read), zstd (pg_receivewal
still rejects it), Windows.

Regards,
Raja Sai Pranav

On Fri, Dec 4, 2026 at 8:47 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Fri, Dec 04, 2026 at 09:37:00AM +0900, Fujii Masao wrote:
> > On Wed, Dec 2, 2026 at 2:40 AM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
> >> Thanks for the report and patch! LGTM.
> >> Barring any objections, I will commit 0001 patch.
> >
> > I've pushed the patch. Thanks!
>
> Thanks for picking up this one. That was on my list of things to look
> at, but well.. Things are what they are.
> --
> Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Manu 2026-12-06 05:01:36 Rebuild partition descriptors from the previous one
Previous Message Chengpeng Yan 2026-12-06 04:38:01 Re: extremely slow planner when DISTINCT clause holds more columns