Read Locks and Write Locks

In database management theory, locking is used to implement isolation among multiple database users txn. This is the “I” in the acronym ACID (Atomicity, Consistency, Isolation, Durability). Locks are applied by a TX (transaction) to data, which may block other TXs from accessing the same data during the TX’s life.

Simple Locking: Two main types of locks can be requested:

  • Shared lock: Read lock i.e. Any other TX(or multiple TXs) can read but not write (lock shares with multiple txs i.e. Shared lock)
  • Exclusive lock: Write lock i.e. No other TX can read or write (lock not shares with any other txs i.e. exclusive lock)

Multiple Locking: Two Phase Locking (2PL) is a concurrency control method that guarantees serializability.

  • A Growing/Expanding/First Phase: locks are acquired and no locks are released.
  • A Shrinking/Contracting/Second Phase: locks are released and no locks are acquired.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)