TOAST Internals and Large Value Storage
Understand how PostgreSQL stores oversized columns and tune compression and external storage thresholds.
Why TOAST Exists
PostgreSQL stores rows on fixed-size 8 KB pages. A single row cannot span multiple pages, so a wide value (a long text, big jsonb, or bytea) would never fit.
TOAST (The Oversized-Attribute Storage Technique) solves this by compressing oversized columns and, if still too large, slicing them into chunks stored in a separate side table.
- Keeps the main heap row small and cache-friendly.
- Lets a logical value far exceed 8 KB (up to ~1 GB).
- Happens automatically and transparently to your queries.
The TOAST Threshold
TOAST kicks in when a row's total size would exceed TOAST_TUPLE_THRESHOLD, which is 2 KB (one quarter of the 8 KB page) by default.
When that limit is crossed, PostgreSQL compresses and/or moves the largest toastable attributes out of line until the row fits under TOAST_TUPLE_TARGET (also ~2 KB).
Only columns of variable-length types (text, varchar, jsonb, bytea, arrays, etc.) are toastable. Fixed-width types like integer or timestamptz are never toasted.
All lessons in this course
- Measuring Table and Index Bloat Accurately
- Reclaiming Space with pg_repack
- Tuning Fillfactor for Update-Heavy Tables
- TOAST Internals and Large Value Storage