Parameter · Write-Ahead Log / Settings
wal_compression
Compresses full-page writes written in WAL file with specified method.
- Default:
off - Type: enum
- Values: pglz · lz4 · zstd · on · off
- Applies: Session (superuser)
In plain words
Full-page images (whole 8 kB pages copied into WAL after each checkpoint) are often the biggest part of WAL. wal_compression compresses them, trading some CPU for less WAL to write, archive and stream.
lz4 is a good default choice when available: fast, and page images often shrink a lot.
For DBAs and operators
Only full-page images are compressed, not the ordinary WAL record payloads. The value names the algorithm: pglz (built-in, slowest), lz4 (needs a build --with-lz4), zstd (needs --with-zstd, best ratio). on is an old spelling of pglz (before PostgreSQL 15 this was a boolean). The PGDG packages include both lz4 and zstd.
Each image is decompressed during replay, on the standby or in recovery. If compression does not shrink an image it is stored uncompressed.
When it helps
- WAL-bound workloads (random updates over a large table) where FPIs dominate.
- Network-limited replication or archiving to object storage.
Measure before and after:
SELECT wal_fpi, pg_size_pretty(wal_bytes) FROM pg_stat_wal;
-- or for a WAL range
pg_waldump --stats=record 000000010000000A0000001FIt can be changed per session by superusers (or roles granted SET), e.g. to compress a big maintenance job only.
How to change it
A superuser (or a role granted SET) can change it per session with SET.