Database Lock

What Is a Lock?

A lock is a method for guaranteeing ordering between transactions.
Here, a transaction means the smallest unit that can be processed independently.
Because each DBMS implements locks in different ways, you need to understand the concept of locks for each DBMS.

What Is a DB Lock?

A DB lock controls access when multiple transactions try to access one piece of data at the same time.

Types of DB Locks

Lock types include Shared Lock and Exclusive Lock, which are also called Read Lock and Write Lock, respectively.

  • Shared Lock(LS, Shared Lock)
    • A lock used when a transaction reads data. It can read data but cannot write data.
  • Exclusive Lock(LX, Exclusive Lock)
    • A lock used when a transaction reads and writes data. It can read and write data.

Exclusive Control

Optimistic Locking

Exclusive control from an optimistic perspective that assumes multiple people will rarely change a resource at almost the same time.

Pessimistic Locking

Exclusive control from a pessimistic perspective that assumes multiple people frequently change the same resource.