# Learn You a Postgres for Great Good!
![[lyapfgg.png]]
Welcome to **Learn You a Postgres for Great Good!** This is a whimsically crafted, narrative-driven exploration of PostgreSQL internals, operations, and workloads.
Inspired by the legendary _Learn You a Haskell for Great Good!_, this guide will demystify the relational database engine through absurd analogies, friendly explanations, and wobbly art!
## The Lazy Elephant
To truly understand Postgres, you must first accept a core truth: **Postgres is incredibly lazy.**
Imagine a highly capable, exceptionally intelligent elephant who woke up this morning and decided he wanted to do the absolute **least amount of work possible** while still technically fulfilling all of his obligations.
- If you ask him to delete a record, he won't actually bring out a trash can and sweep up the page on disk. Too much effort. He'll just cross it off with a sharpie (MVCC) and tell his Roomba (the Autovacuum process) to deal with it later.
- If you ask him for a specific page in a massive book, he absolutely refuses to read the whole book. He builds elaborate, tiny cheat sheets (Indexes) so he only has to look at one thing.
- If you ask him to save data forever and make sure it survives a power outage, actually walking over to the filing cabinet and placing it properly in order is exhausting. Instead, he just frantically scribbles a list of what happened in a sequential diary (the WAL) and promises he'll sort it out into the filing cabinet tomorrow (Checkpointing).
- When you ask him a complex question, he doesn't just start answering. He sits in his tent, looking at statistics and building a battle plan (The Query Planner) to calculate the path of least resistance.
By understanding what the elephant considers "expensive" (reading from disk, talking to the network, fighting over memory), every bizarre quirk of the PostgreSQL architecture suddenly makes perfect, rational sense.
## Table of Contents
### [[Chapter 1/1.0 - The Building Blocks|Chapter 1 - The Building Blocks]]
- [[Chapter 1/1.1 - The Tuple|1.1 The Tuple]]
- [[Chapter 1/1.2 - The Page|1.2 The Page]]
- [[Chapter 1/1.3 - The Table|1.3 The Table]]
- [[Chapter 1/1.4 - MVCC|1.4 MVCC (The Sharpie Ledger)]]
- [[Structures/_Structures|Technical Reference: Structures]]
- [[Architecture/MVCC|Technical Reference: MVCC]]
### [[Chapter 2/2.0 - The Mighty Indexes|Chapter 2 - The Mighty Indexes]]
- [[Chapter 2/2.1 - The B-Tree|2.1 The B-Tree]]
- [[Chapter 2/2.2 - GIN & GiST|2.2 GIN & GiST]]
- [[Chapter 2/2.3 - BRIN|2.3 BRIN]]
- [[Chapter 2/2.4 - Vector Search|2.4 Vector Search]]
- [[Chapter 2/2.5 - The Cost of Fame|2.5 The Cost of Fame]]
- [[Structures/Index|Technical Reference: Index Architecture]]
### [[Chapter 3/3.0 - The Battle for Efficiency|Chapter 3 - The Battle for Efficiency]]
- [[Chapter 3/3.1 - The Lazy General's Map|3.1 The Lazy General's Map]]
- [[Chapter 3/3.2 - Sargability|3.2 Sargability]]
- [[Chapter 3/3.3 - The Soldiers|3.3 The Soldiers]]
- [[Operations/_Postgres Operations|Technical Reference: Operations Overview]]
### [[Chapter 4/4.0 - Safety Without Sweating|Chapter 4 - Safety Without Sweating]]
- [[Chapter 4/4.1 - Write-Ahead Logging|4.1 Write-Ahead Logging]]
- [[Chapter 4/4.2 - The Recovery Parade|4.2 The Recovery Parade]]
- [[Chapter 4/4.3 - Publications & Subscriptions|4.3 Publications & Subscriptions]]
- [[Chapter 4/4.4 - Transactions|4.4 Transactions (The Pinky Swear)]]
- [[Architecture/WAL|Technical Reference: Write-Ahead Log (WAL)]]
- [[Architecture/Transactions|Technical Reference: Transactions]]
### [[Chapter 5/5.0 - The Hunger of Resources|Chapter 5 - The Hunger of Resources]]
- [[Resources/_Resources|Technical Reference: Resources Overview]]
### [[Chapter 6/6.0 - The Waiting Game|Chapter 6 - The Waiting Game]]
- [[Chapter 6/6.1 - Wait Events Overview|6.1 Wait Events Overview]]
- [[Chapter 6/6.2 - Disk Wait|6.2 Disk Wait]]
- [[Chapter 6/6.3 - Locks & Latches|6.3 Locks & Latches]]
- [[Chapter 6/6.4 - Workloads|6.4 Workloads]]
- [[Workloads/_Workloads|Technical Reference: Workloads Overview]]
### [[Chapter 7/7.0 - The Cloud Scales|Chapter 7 - The Cloud Scales]]
- [[Chapter 7/7.1 - Read Replicas|7.1 Read Replicas]]
- [[Chapter 7/7.2 - Cloud Storage|7.2 Cloud Storage]]
- [[Chapter 7/7.3 - Partitioning|7.3 Partitioning]]
- [[Architecture/Cluster|Technical Reference: Cluster Architecture]]
### [[Summary and Epilogue|Summary & Epilogue]]
---
← Home | [[Chapter 1/1.0 - The Building Blocks|1.0 - The Building Blocks →]]