Home

2PL

Two-phase locking (2PL) is a concurrency control method used in database systems to ensure serializability among competing transactions. In 2PL, a transaction's operations are divided into two phases: a growing phase, in which the transaction acquires locks but does not release any, and a shrinking phase, in which the transaction releases locks but does not acquire new ones. The requirement that no lock is released before the end of the growing phase guarantees a structured ordering of access to data items, which supports serializable execution.

Lock types and behavior: 2PL typically uses shared locks (S) for reading and exclusive locks (X) for

Variants: Strict 2PL is a common variant where all locks are held until the transaction commits or

Deadlocks and recovery: Because multiple transactions may wait for locks held by others, deadlocks can occur.

In practice: Many traditional relational databases implement 2PL or strict 2PL as part of their transaction

writing.
A
transaction
may
acquire
an
S
lock
on
a
read
item
and
later
upgrade
to
an
X
lock
for
writing.
Because
of
the
two-phase
rule,
once
a
transaction
begins
releasing
locks
in
the
shrinking
phase,
it
cannot
acquire
new
locks.
Variants
differ
on
whether
lock
upgrades
are
allowed
and
how
strictly
the
growing
and
shrinking
phases
are
enforced.
aborts.
This
simplifies
recovery
and
prevents
cascading
aborts,
at
the
cost
of
reduced
concurrency.
Conservative
2PL,
another
variant,
may
acquire
all
needed
locks
before
a
transaction
proceeds,
further
reducing
the
risk
of
deadlocks.
Some
systems
implement
additional
mechanisms
to
manage
upgrades,
lock
compatibility,
and
deadlock
handling.
Databases
employ
detection
and
resolution
strategies
or
prevention
schemes
such
as
timeouts,
wait-die,
or
wound-wait.
Overall,
2PL
provides
a
robust
path
to
serializable
schedules
but
can
incur
locking
overhead
and
potential
contention.
management,
though
some
modern
systems
favor
alternative
approaches
such
as
multiversion
concurrency
control
(MVCC)
for
different
performance
characteristics.