PostgreSQL Enterprise (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What is TOAST (The Oversized-Attribute Storage Technique)?
senior LevelMost AskedpostgresqlAdvanced Internals
In Simple Words: PostgreSQL pages have a fixed size of 8 KB, and rows cannot span across multiple pages:
- If a column value (e.g. a large text document or JSONB) exceeds 2 KB:
- PostgreSQL automatically triggers TOAST:
- Compresses the large attribute value.
- If still too large, moves the data out-of-line into a hidden auxiliary TOAST table, chunking it into 2 KB pieces.
- Replaces the attribute in the main table with a 18-byte TOAST pointer.
- Standard queries that do not select the large column never read the TOAST table, preserving cache efficiency!