Sobes.tech
Junior — Middle

Can you explain what mutual locking in a SQL database is?

sobes.tech AI

Answer from AI

A deadlock in an SQL database is a situation where two or more transactions block resources that are needed by each other to continue working, and none of them can proceed.

Example: Transaction A has acquired a lock on table 1 and is waiting for a lock on table 2, while transaction B has acquired a lock on table 2 and is waiting for a lock on table 1. As a result, both transactions are 'stuck'.

To avoid deadlocks, the following are usually applied:

  • ordering access to resources;
  • timeouts on lock waiting;
  • using transaction isolation levels considering possible locks.