Avoid streaming zero-filled WAL switch padding

Started by Andrey Borodin18 days ago1 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253331
psql -h localhost -U postgres

Built from patchset v1 (message #1), August 23, 2026 at 08:29 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253331_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253331_1 && git checkout t253331_1

Patchset v1 (message #1) is on t253331_1

Jump to latest
#1Andrey Borodin
amborodin@acm.org

Hi hackers,

pg_switch_wal() fills the remainder of the WAL segment with zeros.
The filesystem can store this efficiently, but walsender still sends all
of those zeros to every standby.

We operate many small clusters that generate little WAL but have strict
statement_timeout requirements. On these clusters, archive_timeout causes
occasional SyncRep latency spikes while the zero-filled tail is streamed.
One user worked around this by adding a continuous dummy write workload that
fills each WAL segment before archive_timeout switches it.

The attached patch adds a compact replication message for zero-filled WAL
padding. Walreceiver reconstructs the tail using truncate-and-extend, so
it is neither transferred over the network nor written to the filesystem.
pg_receivewal and compressed output are supported too.

With a nearly empty default-size segment, this reduces the transfer from
about 16 MB to at most one 128 kB WAL chunk plus a 33-byte message, or
roughly 99.2%.

PFA. WDYT?

Best regards, Andrey Borodin.

Attachments:

t253331_1
v1-0001-Avoid-streaming-zero-filled-WAL-switch-padding.patchapplication/octet-stream; name=v1-0001-Avoid-streaming-zero-filled-WAL-switch-padding.patch; x-unix-mode=0644Download+445-9