Crunchy Data Blog· Christopher Winslett ·
Postgres 19 Compression: Moving the Default TOAST Algorithm from pglz to LZ4
Postgres 19 Compression: from pglz to LZ4
Key Takeaway
Postgres 19 plans to change the default TOAST compression from pglz to LZ4, which has been selectable since Postgres 14 via default_toast_compression = 'lz4' or column-level COMPRESSION lz4.
Why It Matters
In an informal insert test, LZ4 compressed faster, while space savings depended on the data and could still favor pglz.
Technical Breakdown · Distilled from the original source
LZ4 versus pglz
- In the article’s informal test, inserting 2,000 rows with values of about 10 kB took roughly 6 ms with LZ4 versus 50 ms with pglz. Decompression throughput was similar on that dataset, where I/O and memory latency dominated.
- LZ4 uses a 64 kB sliding window versus 4 kB for pglz. In a similar test, a 10,400-byte value compressed to 111 bytes with LZ4 and 186 bytes with pglz, though some data compresses better with pglz.
When heap values are compressed or moved out of line
- Variable-length columns such as
TEXT,BYTEA, andJSONBdefault toEXTENDED, but not every value is compressed. When a row exceeds the default 2,040-bytetoast_tuple_target, Postgres first tries compressing largerEXTENDEDvalues. If the row is still too large, it moves largerEXTENDEDorEXTERNALvalues to TOAST, leaving an 18-byte pointer for each. EXTERNALpermits out-of-line storage without compression;MAINfavors inline compression and moves values out of line only as a last resort. For text, comparepg_column_size(payload)withoctet_length(payload)to distinguish stored size from raw byte length.
B-tree index size limits
- B-tree indexes retain already compressed heap values and try compressing uncompressed variable-length keys above 510 bytes. That is a compression trigger, not an index-entry limit. In the article’s example, LZ4 reduced 5,000 repeated characters to about 38 bytes, allowing the value to be indexed. Concatenated MD5 text compressed poorly, and the insert failed because the index entry exceeded the 2,704-byte limit.
Source: Crunchy Data Blog· crunchydata.com
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.