Re: Compression of bigger WAL records

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
Cc: Japin Li <japinli(at)hotmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, wenhui qiu <qiuwenhuifx(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Compression of bigger WAL records
Date: 2026-10-07 08:46:22
Message-ID: asYG3iYUACmhxU1y@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 06, 2026 at 06:09:38PM +0500, Andrey Borodin wrote:
> The reader now owns a ZSTD_DCtx pointer under USE_ZSTD. Backend builds
> register a reset callback in the reader's memory context, and
> XLogReaderFree() unregisters it before freeing the context. I also
> shortened the compression-side comment.

The declaration of zstd.h is actually quite invasive. Another
possibility would be a forward declaration, like:
typedef struct ZSTD_DCtx_s ZSTD_DCtx;

That gives type enforcement, but perhaps you had the right idea in v9
where we used a void* pointer. I'd still keep that behind a USE_ZSTD,
though, with a zstd-ish naming.

I have also been benchmarking the replay path a bit with something
like the following based on pgbench_accounts, that gives a fixed
number of compressible pages, then run series of VACUUM FULL to
generate WAL mostly made of full page records:
CREATE TABLE t (aid int, bid int, abalance int, filler char(84))
WITH (autovacuum_enabled = off);
INSERT INTO t SELECT i, i / 100000 + 1, 0, ''
FROM generate_series(1, 610000) i;
VACUUM t;
CHECKPOINT;
-- series 10k pages (see via pg_waldump -b).
VACUUM FULL t;

On replay (no fsync, -O2, no asserts, data on tmpfs), I am getting
depending on two different hosts a gain of 1.5% and 3.7% in replay
time (100 VACUUM FULLs, so 1M pages), which is not as much as you have
reported, still that's above noise. For 50 lines of extra code, I'll
take that.

I would be interested in any scripts you may have, and attempt to
reproduce the numbers you have posted. I'll also try some more runs
on a third host (much better CPU and disk that I have around,
locally, not in the cloud).

> We could also avoid this cleanup bookkeeping with a static context, as
> in 0002. For now we only decompress independent images in one call, with
> no history to preserve between records.

With xlogreader.c/h being a pluggable facility for frontend and
backend, storing a static state is not really cool IMO.

> My reasoning was that the writer can still store an uncompressed image,
> whereas replay cannot restore a compressed image without the context.
> I changed this as you suggested, but I still think falling back to an
> uncompressed image is preferable. We are in a critical section.
>
> wal_compression can change during a session, so preparing the workspace
> outside critical sections is not straightforward. This is also the
> hardest and most contentious part of the whole-record and streaming
> compression patches. I'm trying to reuse the FPI compression buffers,
> but still need twice as much buffer space as before. I haven't found a
> better approach. Your thoughts on the allocation strategy would be very
> helpful, even without reviewing those patches.

Hmm. OK, perhaps just storing it uncompressed is better if the
context allocation fails, that's unlikely, still perhaps your
alternative is just better than a plain crash. Please let me ponder
on this part a bit more.

I am attaching a slighly-edited v4 for the time being, which is fine
to me code-wise. I am still planning to do a bit more benchmarking
with replay times, but my first impression is that the numbers seem
good.

So, any thoughts or comments?
--
Michael

Attachment Content-Type Size
v4-0001-Reuse-zstd-decompression-contexts-when-restoring-.patch text/plain 4.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2026-10-07 09:02:05 Re: REPACK (CONCURRENTLY) might keep dropped-column data
Previous Message Haruna Miwa 2026-10-07 08:17:33 Re: [PATCH] psql: avoid CREATE command completion after GRANT/REVOKE CREATE