What are the necessary conditions for a deadlock to occur in a relational database? How does the database engine typically detect and resolve them?
Last updated
A deadlock needs all four Coffman conditions: mutual exclusion, hold and wait, no preemption, and circular wait.
Engines detect deadlocks by finding cycles in a wait-for graph, sometimes with lock-wait timeouts as a fallback. They resolve them by aborting a victim (often the cheapest to roll back), which then retries.
Prevent them by acquiring locks in a consistent order and keeping transactions short.
- https://oneuptime.com/blog/post/2026-01-27-mysql-deadlocks/view
- https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-deadlocks-guide?view=sql-server-ver17
- https://bytepatterns.com/blog/deadlock-detection-wait-for-graph-and-victim-selection
- https://arpitbhayani.me/blogs/database-deadlocks/
- https://intl.cloud.tencent.com/document/product/1035/48632
- https://www.cybertec-postgresql.com/en/postgresql-understanding-deadlocks/
- https://oneuptime.com/blog/post/2026-03-31-mysql-what-is-deadlock/view
- https://www.mafiree.com/blog/mysql-deadlock-analysis