Steal/Force Matrix
Before diving into WAL mechanics, you must understand two orthogonal buffer management policies that fundamentally determine what kind of recovery protocol a database needs. Every database system makes these two choices, and the combination dictates the entire recovery architecture.
Two Independent Policy Axes
Section titled “Two Independent Policy Axes”Steal vs No-Steal: “Can we evict uncommitted dirty pages?”
Section titled “Steal vs No-Steal: “Can we evict uncommitted dirty pages?””The buffer pool has limited memory. When it’s full and a new page is needed, should the system be allowed to steal (evict) a dirty page from an uncommitted transaction?
| Policy | Definition | Implication |
|---|---|---|
| Steal | Buffer manager CAN flush uncommitted dirty pages to disk | Requires UNDO capability — must reverse changes from aborted transactions that reached disk |
| No-Steal | Buffer manager must KEEP uncommitted dirty pages in memory | No undo needed, but memory pressure can stall transactions |
Force vs No-Force: “Must all pages be on disk at commit?”
Section titled “Force vs No-Force: “Must all pages be on disk at commit?””When a transaction commits, must all its dirty pages be forced to disk before acknowledging the client?
| Policy | Definition | Implication |
|---|---|---|
| Force | ALL modified pages written to disk at COMMIT | No REDO needed — committed data is always on disk |
| No-Force | Modified pages can stay in memory after COMMIT | Requires REDO capability — committed data might only be in the log |
The 2×2 Matrix
Section titled “The 2×2 Matrix”Click each cell below to explore its trade-offs:
Interactive: Steal/Force Policy Matrix
Click each cell to explore its implications. The highlighted cell is what virtually all production databases use.
Steal + No-Force
Why Steal + No-Force Wins
Section titled “Why Steal + No-Force Wins”Virtually every production database uses Steal + No-Force despite requiring the most complex recovery (both REDO and UNDO). Here’s why:
Performance Argument
Section titled “Performance Argument”No-Force eliminates synchronous random I/O at commit time:
- With Force: COMMIT must flush N dirty pages → N random disk writes → slow
- With No-Force: COMMIT only fsyncs the WAL → 1 sequential write → fast
Steal prevents memory stalls:
- With No-Steal: Long transactions pin pages in memory → buffer pool exhaustion
- With Steal: Buffer manager freely evicts any page → predictable memory usage
Performance Impact: No-Steal Steal ──────── ───── Force │ Worst (slow │ Moderate │ commit + memory │ (slow commit, │ pressure) │ free memory) │ │ No-Force │ Moderate (fast │ ★ Best (fast │ commit, memory │ commit + free │ pressure) │ memory)The WAL Protocol Makes It Safe
Section titled “The WAL Protocol Makes It Safe”The entire WAL protocol exists to make Steal + No-Force safe:
-
WAL Rule (Write-Ahead): Before any dirty page is written to disk, all log records up to that page’s LSN must be flushed. This ensures we can always REDO committed changes.
-
Force-at-commit for the LOG (not data): WAL is force-written at commit. The log is the durability guarantee, not the data pages.
-
Undo information in the log: Each log record contains enough information to reverse the change, enabling rollback of stolen uncommitted pages.
How Real Systems Choose
Section titled “How Real Systems Choose”| System | Steal? | Force? | Recovery Model |
|---|---|---|---|
| PostgreSQL | Steal | No-Force | ARIES-style redo + undo |
| MySQL/InnoDB | Steal | No-Force | Redo log + undo log |
| SQLite (WAL mode) | Steal | No-Force | WAL replay + rollback |
| Oracle | Steal | No-Force | Redo + undo tablespaces |
| SQL Server | Steal | No-Force | ARIES-based recovery |
| MongoDB (WiredTiger) | Steal | No-Force | Journal replay |
| RocksDB | N/A* | No-Force | WAL replay to memtable |
*LSM engines like RocksDB don’t have a traditional buffer pool — writes go to memtable (memory) then flush to SSTables. The WAL protects unflushed memtable data.
The Steal Problem in Detail
Section titled “The Steal Problem in Detail”When a dirty page from an uncommitted transaction is stolen (written to disk), what happens if that transaction later aborts?
Timeline:1. T1: Modify Page 5 (in buffer pool)2. Buffer pool full — Page 5 stolen to disk (T1 still active!)3. T1: ABORT4. Problem: Page 5 on disk has T1's uncommitted change!Solution: UNDO. The WAL contains the before-image (or enough info to reverse the change). During abort or crash recovery, the undo pass reverses all changes from uncommitted transactions that reached disk.
The No-Force Problem in Detail
Section titled “The No-Force Problem in Detail”When a transaction commits but its dirty pages haven’t been flushed:
Timeline:1. T2: Modify Page 3, Page 7 (in buffer pool)2. T2: COMMIT → WAL fsynced ✓3. ⚡ CRASH — Pages 3, 7 never written to disk4. Problem: Committed data only exists in WAL!Solution: REDO. During crash recovery, the redo pass scans the WAL forward and re-applies all changes from committed transactions whose data pages are stale.
Connecting to ARIES
Section titled “Connecting to ARIES”The ARIES recovery algorithm (which we’ll study in depth in Chapter 3) is specifically designed for the Steal + No-Force policy:
| ARIES Phase | Handles | Policy |
|---|---|---|
| Analysis | Determines what needs redo/undo | Both |
| Redo | Re-applies committed changes missing from disk | No-Force |
| Undo | Reverses uncommitted changes present on disk | Steal |
Key Takeaways
Section titled “Key Takeaways”- Steal = uncommitted pages can be on disk → needs UNDO
- No-Force = committed pages might not be on disk → needs REDO
- Steal + No-Force requires both REDO and UNDO but gives the best performance
- Every production database uses Steal + No-Force with WAL to make it safe
- The WAL protocol is the force-at-commit for the log, not the data files
Quick Quiz: Steal/Force Matrix
-
What does “Steal” mean and what recovery capability does it require? → Steal means the buffer manager can evict uncommitted dirty pages to disk. It requires UNDO capability.
-
Why is No-Force desirable despite needing REDO? → No-Force means COMMIT only needs to fsync the WAL (sequential, fast) instead of all dirty pages (random I/O, slow).
-
Can you have Steal without WAL? → No — without WAL, stolen uncommitted pages can’t be undone after a crash. The before-images in the WAL are what makes undo possible.
-
What would happen if PostgreSQL used a No-Steal policy? → Long transactions would pin pages in the buffer pool. Under memory pressure, new transactions would stall waiting for buffer space. OOM scenarios become likely.