IT lexicon › Database › Two-phase locking

Two-phase locking

Database På svenska → Updated: 2026-05-27

Classic concurrency control algorithm: the transaction locks objects it touches, releases all locks only at commit. "Two phases" = growing phase (acquire locks) + shrinking phase (release). Guarantees serializability but risks deadlock.

Strict 2PL (S2PL): holds exclusive locks until end, guarantees recoverability. Rigorous 2PL: holds all locks until end. MySQL InnoDB uses S2PL for Serializable isolation. Competitor: MVCC + snapshot isolation (Postgres default) — locks only writes, reads see a consistent snapshot without blocking. 2PL has higher lock contention but simpler reasoning. Modern distributed DBs use Optimistic Concurrency Control (Cockroach) or MVCC (Postgres, Spanner). Classically taught in every DB course.

← Back to the lexicon