# 5.1 The Warming Rack (Shared Buffers) ![The Warming Rack](assets/arch_shared_buffers_rack.png) In Chapter 1, we saw how every suitcase (row) is packed into an 8KB **[[Chapter 1/1.2 - The Shipping Container (The Page)|Page]]**. But the elephant is far too lazy to carry these pages up from the **frozen pantry** every time someone asks a question. Instead, he keeps a **Warming Rack** right in the middle of the room. This rack is called the **Shared Buffers**. If a block of data is going to be accessed frequently, it must be kept warm and ready. ## The Microwave Mentality The Warming Rack is the most expensive piece of furniture in the depot. It is where the most popular pages live, kept warm and ready for instant access. When a staff member needs a page, he first checks the rack. If it's there (a **Buffer Hit**), he can read it in the time it takes to blink. If it's not (a **Buffer Miss**), he has to put on his winter coat and spend four months walking to the **pantry** to fetch it. ## The Clock Sweep (Who Stays Warm?) Because the rack is small and the depot is infinite, the elephant must eventually decide which pages to kick off the rack to make room for new ones. He uses a clever game called the **Clock Sweep Algorithm**. It is a strict recipe for rotation: 1. Every page on the rack has a **Usage Count** (a tiny number from 0 to 5). Think of it as how many tea-party invitations the page has. 2. The elephant walks around the rack like a clock hand. 3. Every time he passes a page, he decrements its count by 1. 4. If he finds a page with a count of **0**, he kicks it off the rack and puts a new page there. 5. But if a staff member accesses a page, its count is instantly bumped back up! This ensures that "Hot" pages (the ones everyone is looking at) stay warm and cozy, while legacy data slowly cools down and returns to the frozen pantry. ### The Size of the Rack You can ask the elephant exactly how large his Warming Rack is with a simple command: ```sql -- How many pages can we keep warm? SHOW shared_buffers; -- Results: -- shared_buffers -- ---------------- -- 128MB ``` If you want to see exactly *which* suitcases are currently warm, you can use the **`pg_buffercache`** extension. It’s like a thermal camera for the depot! --- [[Chapter 5/5.0 - The Hunger of Resources (Memory & Disk)|← 5.0 - The Hunger of Resources]] | [[Chapter 5/5.0 - The Hunger of Resources (Memory & Disk)|↑ 5.0 - The Hunger of Resources]] | [[Chapter 5/5.2 - The Private Desk (Work Mem)|5.2 - The Private Desk β†’]]