# 1.6 The Separate Trailer (TOAST) ![The TOAST Trailer](assets/toast_dinosaur.png) Every now and then, a patron shows up at the **Elephant Cafe** with a piece of luggage so massive—a multi-megabyte recipe for a galaxy-sized cake, or a JSON blob containing the life story of every capybara in the city—that it simply **will not fit** in a standard suitcase. Now, remember the elephant's fundamental constraint: his **[[Chapter 1/1.2 - The Shipping Container (The Page)|8KB Gloves]]**. He refuses to pick up anything larger than 8KB. But even a suitcase that is 7KB is a problem, because only one of them would fit in a shipping container, leaving the elephant very grumpy about the inefficiency. ## The 2KB Rule To keep his life simple, the elephant has a secret rule: **If a single item in a suitcase is larger than 2KB, it’s time to call the trailer.** This threshold (technically `TOAST_TUPLE_THRESHOLD`) is the elephant's way of ensuring that every shipping container can still hold multiple suitcases, allowing him to grab more data with every movement of his trunk. ## TOAST: The Oversized-Attribute Storage Technique Instead of shoving the giant item into the main suitcase, the elephant uses **TOAST**. 1. **The Hack-and-Pack**: He takes the giant item and chops it into **2KB chunks**. 2. **The Separate Trailer**: He stores these chunks in a completely separate Depot building called a **TOAST Table**. This building has its own blueprints and its own shipping containers. 3. **The Claim Check**: In the original suitcase, where the giant item should have been, he leaves a tiny, 20-byte **Claim Check** (an OID pointer). When you ask for the data, the elephant sees the Claim Check, sighs, walks over to the TOAST building, gathers all the chunks, tapes them back together (and sometimes uncompresses them), and brings the final result to your table. ## The Three Styles of Packing The elephant can handle big items in three ways, depending on his mood (and your settings): | Style | Metaphor | Technical Policy | | :----------- | :---------------------- | :---------------------------------------------------------------------------------------- | | **PLAIN** | **Strict Suitcase** | No TOAST allowed. If it doesn't fit, the elephant throws a tantrum (Error). | | **EXTENDED** | **Compress & Trailer** | Try to compress it first. If it's still big, move it to the trailer. (Default for `TEXT`) | | **EXTERNAL** | **Straight to Trailer** | No compression. Just put it in the trailer immediately. | ## Why it matters Because of TOAST, the main building (the **Main Fork**) stays lean and fast. The elephant can run through the depot at high speed because he only has to look at the "big stuff" when you explicitly ask for it. If you are just scanning names and IDs, the elephant never has to walk to the TOAST trailer. This is why Postgres remains snappy even when you store massive PDFs or giant JSON documents—the elephant is just ignoring the "heavy lifting" until the very last second. --- | ← Previous | ↑ Table of Contents | Next → | | :--------------------------------------------------------------------------- | :-------------------------------------------- | :--------------------------------------------------------------------- | | [[Chapter 1/1.5 - The Sharpie Ledger (MVCC)\|1.5 The Sharpie Ledger (MVCC)]] | [[Learn You a Postgres for Great Good\|Home]] | [[Chapter 2/2.0 - The Mighty Indexes\|Chapter 2 - The Mighty Indexes]] |