Avoid streaming zero-filled WAL switch padding

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: pgsql-hackers mailing list <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Avoid streaming zero-filled WAL switch padding
Date: 2026-08-06 07:49:26
Message-ID: 0E59ED14-DE1B-41D9-886D-FE409BF0A056@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Attachment Content-Type Size
v1-0001-Avoid-streaming-zero-filled-WAL-switch-padding.patch application/octet-stream 21.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message John Naylor 2026-08-06 07:55:24 Re: [PATCH] Use ssup_datum_*_cmp for int2, oid, and oid8 sort support
Previous Message Heikki Linnakangas 2026-08-06 07:43:47 Re: [Patch]The Case For WAL-Logging pg_upgrade