A deadlock occurs when two or more transactions each hold a lock that another one needs, creating a circular wait that cannot resolve on its own. The database detects it and aborts one transaction as the victim.
Why it matters
Deadlocks appear as sporadic errors under concurrent load, such as "Deadlock found when trying to get lock; try restarting transaction" in MySQL. They are not bugs in the database but a sign of conflicting access order. They are normal enough that applications should be ready to retry the failed transaction.
Example
Transaction A: lock row 1, then wants row 2
Transaction B: lock row 2, then wants row 1
Both wait forever. The database kills one, and the other proceeds. Updating rows in a consistent order (for example by ascending id) in every transaction prevents this particular pattern.
Common mistakes
- Not retrying after a deadlock error, so users see a failure that would succeed on a second attempt.
- Holding transactions open across slow operations, which widens the window for conflicts.
- Confusing a deadlock with a simple lock wait timeout, where one transaction is just slow.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.