# 4.5 The Looking Glass Windows (Isolation Levels) ![Isolation Levels](assets/arch_isolation_windows.png) Now that we understand the [[Chapter 4/4.4 - The Pinky Swear (Transactions)|Pinky Swear]], we need to talk about the **view**. When you step into a **Looking Glass Room** (a Transaction), the Lazy Elephant has to decide exactly how much of the outside Depot you are allowed to see through the windows. This is known as the **Isolation Level**, and Postgres offers three distinct types of windows. ## 1. Read Committed (The Standard Window) This is the default view. The window is clear, but it only shows what people have *finished* (committed). Imagine you look out the window and see a red suitcase sitting on a cart. You blink, and in that split second, another elephant commits a change that swaps it for a blue suitcase. When you look again, the red one is gone! This is called a **Non-repeatable Read**. Because the window is "live" to committed changes, your view can change mid-transaction. It’s fast, it’s low-effort for the elephant, and for 99% of tasks, it’s exactly what you need. ## 2. Repeatable Read (The Magic Painting) If you need more stability, you ask for a **Repeatable Read**. The moment you step into the room, the elephant takes a high-resolution Polaroid of the entire Depot and tapes it over the window. This is **Snapshot Isolation**. No matter how many suitcases are moved, added, or burned outside, your "Magic Painting" never changes. You see the world exactly as it was the moment your pinky swear began. Even if you look a thousand times, that red suitcase will stay red. Be warned: if you try to update a suitcase that someone else changed while you were looking at your painting, the elephant will scream and cancel your transaction! He hates paradoxes. It’s like a bouncer who ensures that even if a hundred elephants are working, the result is the same as if they had walked through the door **one at a time, in a single-file line**. It is perfectly safe, but it makes the elephant very nervous (and can slow things down if everyone reaches for the same suitcases). ### Choosing Your Window You can tell the elephant exactly which window you want for your session or your next transaction: ```sql -- Checking the current view SHOW transaction_isolation; -- Changing the window for the next Pinky Swear SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; -- ... your stable view begins here COMMIT; ``` Remember: the clearer the window, the more work the elephant has to do to keep it clean! --- [[Chapter 4/4.4 - The Pinky Swear (Transactions)|← 4.4 - Transactions]] | [[Chapter 4/4.0 - Safety Without Sweating (The Write-Ahead Log)|↑ 4.0 - Safety Without Sweating]] | [[Chapter 4/4.6 - The Infinite Calendar (Transaction ID Wraparound)|4.6 - The Infinite Calendar →]]