What is Two-phase locking (2PL)?

A concurrency control method in which each transaction has two phases, one acquiring locks and one releasing them, and acquires no new locks once it starts releasing. It guarantees serializability, but deadlocks can still occur.

Japanese name: 2相ロック

Two-phase locking (2PL) appears in 1 practice question across 1 topic, including Database Basics.

Field: Database Basics

Try it: questions about Two-phase locking (2PL)

Which correctly describes two-phase locking (2PL), used for concurrency control of transactions?

  1. AA transaction may alternate between acquiring and releasing locks any number of times. This guarantees that deadlocks never occur
  2. BLocks are taken only for writes, not for reads. This prevents every problem, including dirty reads
  3. COnce a transaction releases any lock, it acquires no new locks afterwards. This guarantees that concurrent execution gives the same result as serial execution, but deadlocks can still occur
Show answer and explanation

Answer: C. Once a transaction releases any lock, it acquires no new locks afterwards. This guarantees that concurrent execution gives the same result as serial execution, but deadlocks can still occur

Under two-phase locking (2PL), each transaction has two phases, a phase in which it acquires the locks it needs one after another (the growing phase) and a phase in which it releases them (the shrinking phase), and once it starts releasing locks, it acquires no new ones. If every transaction follows this rule, the result of concurrent execution is guaranteed to be the same as executing the transactions one at a time in some order (serializability). However, it cannot prevent a deadlock, in which two transactions each wait for the other to release a lock, so the DBMS detects deadlocks and handles them, for example by rolling back one of the transactions. In practice, strict two-phase locking, which holds exclusive locks until commit, is commonly used; it also prevents other transactions from reading uncommitted data.

Two-phase locking (2PL) in the explanations

Questions that mention Two-phase locking (2PL) (1)

  1. Which correctly describes two-phase locking (2PL), used for concurrency control of transactions?

Books on Database Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Transaction Deadlock ACID properties Database index Database view E-R diagram Foreign key Isolation level Normalization NoSQL

Back to the glossary