Deadlock found when trying to get lock; try restarting transaction
Two transactions waited on each other’s locks; the database killed one so the other could continue.
Deadlock found when trying to get lockdeadlock detectedTransaction was deadlocked Meaning
Deadlocks are normal in busy OLTP systems. The database picks a victim and rolls it back (MySQL 1213, PostgreSQL 40P01, SQL Server 1205). Applications should retry the victim transaction — and reduce how often it happens.
Common causes
- Transactions updating the same rows in different orders
- Long transactions holding locks
- Missing indexes causing range/gap locks on many rows
- Bulk updates competing with OLTP writes
⚡ Quick fix
- Retry the transaction (with small backoff) on deadlock errors
- Access tables/rows in a consistent order
- Keep transactions short
- Add indexes so updates lock fewer rows
Detailed fix by platform
MySQL
SHOW ENGINE INNODB STATUS\G→ LATEST DETECTED DEADLOCK shows both queries.
PostgreSQL
- Enable
log_lock_waitsand check the server log for the deadlock detail.
How to diagnose
- Queries — Which two statements deadlocked?
- Order — Do they lock rows in different orders?
- Indexes — Are WHERE clauses indexed?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026