Sobes.tech
Senior

What types of locks exist at the database level?

sobes.tech AI

Answer from AI

Databases have different types of locks that ensure data integrity and consistency during concurrent access. The main types of locks:

  • Row-level locks — lock individual records, minimizing contention.
  • Table-level locks — lock the entire table, providing coarser control.
  • Page-level locks — lock data pages, an intermediate level.

By lock type:

  • Shared lock (S-lock) — allows reading but blocks writing.
  • Exclusive lock (X-lock) — blocks both reading and writing.

There are also:

  • Intent locks — used to indicate the intention to acquire a coarser lock.
  • Deadlock — a situation where transactions mutually block each other.

Different DBMSs may have different mechanisms and names, but conceptually, locks serve to manage concurrent access and maintain transaction isolation.