How PostgreSQL Compression Works & How to Reduce Database Storage
PostgreSQL is the world's most loved relational database, but as analytical event streams, time-series metrics, and transactional tables scale into millions of rows, database storage bills can explode on AWS RDS, Aurora, and managed cloud providers.
In this deep dive, we break down how PostgreSQL compression actually works under the hood, what options you have natively, and how to achieve up to 88% storage reduction.
How Does PostgreSQL Compression Work?
PostgreSQL uses TOAST (The Oversized-Attribute Storage Technique) to automatically compress or split variable-length column values (such as TEXT, JSONB, and BYTEA) whenever a row exceeds roughly 2 KB inside a standard 8 KB heap page.
Fixed-width columns (INTEGER, BIGINT, TIMESTAMP, UUID) are not compressed by TOAST on standard heap pages unless moved into a specialized columnar engine.
What Compression Options Does PostgreSQL Have?
Built-in PostgreSQL offers three native compression algorithms across three subsystems:
-
pglz— Legacy default TOAST column compression (higher CPU overhead, slower decompression). -
lz4— High-speed TOAST column compression (PostgreSQL 14+) and WAL compression (PostgreSQL 15+). -
zstd(Zstandard) — High-ratio compression for WAL full-page writes (wal_compression = zstd, PostgreSQL 15+) and backups (pg_basebackup --compress=zstd&pg_dump, PostgreSQL 15/16+).
PostgreSQL Compression Options Compared
| Subsystem / Layer | Available Algorithms | Config / SQL Syntax | Min PG Version | Typical Reduction & Trade-Off |
|---|---|---|---|---|
TOAST Column Storage (TEXT, JSONB > 2 KB) | pglz (default), lz4 | SET default_toast_compression = 'lz4'; | PG 14+ (lz4) | 1.5×–3× on large attributes. lz4 decodes 3×–5× faster than pglz with minimal CPU overhead. |
| WAL Full-Page Images (Write-Ahead Log) | pglz, lz4, zstd | wal_compression = 'zstd' in postgresql.conf | PG 15+ (lz4, zstd) | 30%–60% smaller WAL volume. Cuts I/O spikes after checkpoints and lowers replication bandwidth. |
| Base Backups & Logical Dumps | gzip, lz4, zstd | pg_basebackup -Z zstd:5 or pg_dump -Fc -Z zstd | PG 15+ / 16+ | 3×–6× smaller backups. zstd beats gzip on both compression ratio and backup speed. |
| B-Tree Indexes | Key Deduplication | Enabled by default (deduplicate_items = on) | PG 13+ | 20%–60% smaller non-unique indexes by collapsing duplicate keys. |
| Full-Table Columnar Storage | Columnar Dictionary, Delta, Bit-packing | External wire-compatible columnar engine (KOLMOS) | Any (via Port 5432) | 4×–8× smaller total footprint. Compresses every column type, not just large strings. |
4 Practical Steps to Cut Storage Costs Immediately
1. Upgrade TOAST Compression to LZ4
If you are running PostgreSQL 14 or newer, immediately switch your default TOAST compression from pglz to lz4:
SET default_toast_compression = 'lz4'; ALTER TABLE production_events ALTER COLUMN payload SET COMPRESSION lz4; 2. Enable Zstandard for WAL
On PostgreSQL 15+, enable zstd WAL compression in postgresql.conf:
wal_compression = zstd This reduces WAL write amplification by 30% to 50% without impacting transactional commit latency.
3. Eliminate Table Bloat with Autovacuum Tuning
Compressing tables that contain dead tuples wastes disk and CPU. Ensure autovacuum_vacuum_scale_factor is tuned down from 0.2 to 0.05 on high-churn tables:
ALTER TABLE user_activity SET (autovacuum_vacuum_scale_factor = 0.05); 4. Move Historical Analytical Data to Columnar Storage
Row-oriented 8KB heap pages are fundamentally inefficient for historical tables and analytics because reading even one column forces the entire 8KB page into RAM.
For high-volume append logs, time-series metrics, and transactional history, storing data in columnar format cuts storage footprints by up to 88% and offloads to zero-egress cloud object storage.
Read the full in-depth guide, benchmarks, and interactive storage calculator on kolmos.dev/blog and explore our live benchmark suite at kolmos.dev/benchmarks.

