Sobes.tech
Junior — Middle

Can you explain the mechanism of pessimistic resource locking in database management systems?

sobes.tech AI

Answer from AI

Pessimistic locking is a concurrency control mechanism in DBMS where a transaction immediately acquires the necessary locks and holds them until completion (commit or rollback). This prevents conflicts and ensures isolation but may reduce parallelism.

Example of operation:

  • A transaction requests an exclusive lock on a row or table.
  • If the lock is available, it is granted; otherwise, the transaction waits for it to be released.
  • All locks are held until the end of the transaction to prevent 'dirty reads' and other anomalies.

This approach is simple and reliable but can lead to deadlocks, which need to be handled separately.