Two-Phase Locking (2PL) Protocol: Short Notes for Concurrency Control

Two-Phase Locking (2PL) Protocol: Short Notes for Concurrency Control

Verified Sources
Sep 12, 2026

Two-Phase Locking (2PL) is a locking-based concurrency control protocol used to ensure that interleavings of transactions remain conflict-serializable. The core idea is that each transaction follows a strict two-stage discipline for acquiring and releasing locks: it first grows its set of locks, and only then shrinks by releasing locks. In particular:

During the growing phase, a transaction may acquire (shared/exclusive) locks, but it must not release any held lock. Once it enters the shrinking phase, it may release locks, but it must not acquire any new locks. This separation prevents “lock conversion/release-then-reacquire” patterns that can otherwise produce schedules that are not conflict-serializable.

Key terms:

  • Two-Phase Locking
  • Growing phase
  • Shrinking phase
  • Shared lock (S-lock)
  • Exclusive lock (X-lock)

Limitation note: I’m unable to perform the required web searches right now due to a tool usage limitation (external sources/citations are unavailable). The content below is based on standard database concurrency-control theory.

Two-Phase Locking (2PL) - Growing and Shrinking Phases (Conceptual)

Locking compatibility and why 2PL works

2PL relies on the compatibility rules of lock types:

  • S-locks are compatible with S-locks (multiple readers allowed).
  • X-locks are incompatible with S-locks and X-locks (writers require exclusive access).

Let’s model the state of a transaction TiT_i as the set of locks it holds over time. The 2PL discipline enforces that:

  • every lock acquisition for TiT_i occurs before its first lock release,
  • after the first release, TiT_i cannot acquire new locks.

This ordering property is what supports the proof that 2PL schedules are conflict-serializable: intuitively, it prevents cycles in the precedence (conflict) graph that arise when transactions alternate between acquiring and releasing locks.

Mermaid view of the “no switching back” rule:

How a Transaction Follows 2PL

  1. 1
    Step 1

    As TiT_i executes, it requests S-locks for reads and X-locks for writes. It cannot release any lock yet.

  2. 2
    Step 2

    Once TiT_i releases any lock, it permanently transitions to shrinking.

  3. 3
    Step 3

    After entering shrinking, TiT_i may release locks but must not request any additional locks.

  4. 4
    Step 4

    At the end, remaining locks are released by transaction completion (consistent with the shrinking rule).

Minimal and common variations: Strict 2PL (rigorous timing)

A widely used strengthening is Strict 2PL (also called rigorous 2PL). The key rule is:

  • A transaction holds all X-locks until it commits or aborts (i.e., it cannot release write locks early).

This design prevents cascading aborts, because no other transaction can read uncommitted (dirty) data written by a transaction that later aborts.

Key terms:

  • Strict 2PL
  • Cascading abort
  • Dirty read
  • Recoverability

Callout intuition: strict 2PL is more conservative (can reduce concurrency) but is very safe for recovery.

Pro Tip

When writing short notes for exams, always mention: (1) growing vs shrinking phases, (2) “no lock acquisition after first unlock,” and (3) optional upgrade to strict 2PL to prevent cascading aborts.

Common Pitfall

Don’t confuse 2PL with mere “lock correctness.” The two-phase constraint (acquire then release only) is what guarantees conflict-serializability; releasing early without a shrinking phase can break the guarantee.

2PL Transaction Timeline

Growing

Phase 1

Acquire locks (S for read, X for write). No releasing."

First lock release

Boundary

Transaction enters shrinking phase here."

Shrinking

Phase 2

Release locks. No further lock acquisitions."

Commit/Abort

End

Final completion; locks are released (consistent with shrinking)."

Quick Exam-Ready Notes

Effect of 2PL Variants on Concurrency vs Safety

Higher safety usually reduces concurrency due to stricter lock holding.

Knowledge Check

Question 1 of 4
Q1Single choice

In Two-Phase Locking (2PL), what is the key restriction after a transaction releases its first lock?