Sobes.tech
Senior

What types of locks are there in a database? Which were used more often?

sobes.tech AI

Answer from AI

In databases, there are several types of locks used to ensure data integrity and prevent conflicts during concurrent access:

  • Row-level locks — lock individual table rows. They allow a high degree of concurrency since only specific records are locked.
  • Page-level locks — lock data pages (groups of rows). Used for optimization but can reduce concurrency.
  • Table-level locks — lock the entire table. Simple but significantly limit concurrency.
  • Database-level locks — lock the entire database, used rarely and only in special cases.

By lock type:

  • Shared lock (S-lock) — allows reading, blocks writing.
  • Exclusive lock (X-lock) — allows only the current write operation, blocks other operations.

Most modern DBMSs use row-level locks as they provide a balance between data integrity and performance, allowing multiple transactions to operate in parallel without conflicts.