# 4.2 The Recovery Parade

Imagine a sudden, violent thunderclap. The power in the warehouse flickers and
dies. The elephant, who was in the middle of three different tasks, falls asleep
instantly.
When the power returns and the elephant wakes up, he has **amnesia**. He doesn't
remember what was in his head, what was on his desk (Memory), or which suitcases
he was currently moving.
## The Morning After
The Filing Cabinet (the Disk) is now in a "dirty" state. Some suitcases are
halfway moved, some are missing, and the whole warehouse is a mess. But the
elephant doesn't panic. He reaches into his pocket and pulls out the **Pocket
Diary (WAL)**.
The diary survived the storm because of the `fsync` handshake we talked about in
[[Postgres/Chapter 4/4.1 - The Pocket Diary (WAL & fsync)]].
## The Redo Log
The elephant begins the **Recovery Parade**. He starts at the very last "safe
point" (the last [[Postgres/Architecture/WAL#Checkpoints|Checkpoint]]) and reads
every single scribble in the diary from that point forward.
_"I changed Row 5 to Red..."_ -> The elephant checks Row 5. If it's still Blue,
he makes it Red. _"I moved Suitcase 10 to Shelf B..."_ -> He moves the suitcase.
He "redoes" every single successful action that was confirmed before the power
went out. He also looks for any tasks that were **not** finished—those where the
user hadn't received a thumbs-up yet. For these, he performs an **Undo** (or
simply ignores them), ensuring that the warehouse returns to a perfectly
consistent state.
## The Miracle of Consistency
This parade is why Postgres is so famously reliable. You can pull the plug, kick
the server, or have a catastrophic kernel crash, and as long as the Pocket Diary
is intact, the elephant will eventually rebuild the world exactly as it was
promised to be.
This recovery process happens automatically every time Postgres starts up. If
you see a message saying "database system was not shut down cleanly; automatic
recovery in progress," don't worry—that's just the elephant finishing his
morning reading.