Module 5 · Transactions and concurrency control
Episode 35 Two-Phase Locking
▶ This video is coming to YouTube soon.
Why locking every row still loses money, and how two-phase locking fixes it: shared and exclusive locks, the growing and shrinking phases, why lock points make every schedule conflict-serializable, cascading aborts and strict 2PL, and IS/IX/SIX intention locks. Then the real thing in Postgres: pg_locks, pgrowlocks, FOR SHARE vs FOR UPDATE, and LOCK TABLE modes blocking each other.
Chapters
- 0:00Intro
- 0:15Lock everything, still lose money
- 0:36Locking each operation isn't enough
- 1:23Two-phase locking fixes the lost update
- 2:12Grow, lock point, shrink
- 3:04Why 2PL never makes a cycle
- 3:32Cascading aborts, and strict 2PL
- 4:21Intention locks: lock at the right size
- 5:14The full compatibility matrix
- 5:46The code: a lock request
- 6:15Postgres's table locks, and their textbook cousins
- 6:50Proof: what a transaction holds
- 7:46Proof: FOR SHARE shares, FOR UPDATE waits
- 8:40Proof: table lock modes conflict
- 9:38Recap
- 10:05Next: Deadlocks