![[chap_7_waiting_game.png]]
# Chapter 7: The Waiting Game (Workloads & Locking)
What happens when a thousand incredibly lazy, highly opinionated elephants are all crammed into the same room, all trying to read the exact same cheat sheet, or write in the exact same frantic diary, at the exact same moment?
They bump into each other. They glare. And worst of all, they have to wait in line.
A "Workload" is simply the physiological measurement of the elephant sighing heavily while waiting for its turn. To analyze why your database is slow, you must first determine which of the **Two Modes of Misery** the elephant is currently in:
### 1. The Sweat (CPU Bound)
Sometimes, the room is silent because the elephant is thinking so hard his ears are steaming. He is performing a massive [[Sort]], calculating a billion Regular Expressions, or frantically zipping two huge lists together in a [[HashJoin]]. He isn't waiting for anyone else; he is simply at the absolute limit of how fast his brain can work. In this state, you won't see many "Wait Events"—you'll just see a very exhausted, very busy elephant.
### 2. The Sigh (IO Bound)
Other times, the elephant is completely still. He is standing by the elevator, tapping his foot, waiting for a [[Page]] to be brought up from the frozen basement ([[Disk IO]]). He cannot continue his work until he has that data in his hand. This is where the "Waiting Game" truly begins.
Postgres categorizes every possible reason an elephant might be frozen in place. Sometimes, the blockade is heavy and structural, like a massive iron [[Lock]] clamped across a table by someone performing an ALTER operation, completely stopping the queue. Other times, the friction is almost microscopic—like thousands of millisecond-long [[LWLock|LWLocks]] constantly clicking open and shut as elephants politely shove past each other to glance at a shared memory buffer.
The database meticulously records exactly why it is paralyzed. Is it suffering from crippling [[IO|Disk IO]] because the filing cabinet is jammed? Is it sitting idle in a [[Client]] state, peacefully ignoring the world while it waits for you to send the next command? Is it tangled in complex [[IPC]] (Inter-Process Communication) as massive parallel workers try to yell messages to each other across the room?
By examining these wait events, you can pinpoint exactly which animal in the crowd is refusing to drop their padlock, or if the elevator to the basement is simply too slow for the crowd.