Deadlock SQL Origin: Data Last updated 13 Oct 2026

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.

Exact message you may see Deadlock found when trying to get lockdeadlock detectedTransaction was deadlocked
Seen on: MySQL PostgreSQL

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

  1. Retry the transaction (with small backoff) on deadlock errors
  2. Access tables/rows in a consistent order
  3. Keep transactions short
  4. Add indexes so updates lock fewer rows

Detailed fix by platform

MySQL

  1. SHOW ENGINE INNODB STATUS\G → LATEST DETECTED DEADLOCK shows both queries.

PostgreSQL

  1. Enable log_lock_waits and check the server log for the deadlock detail.

How to diagnose

  1. Queries — Which two statements deadlocked?
  2. Order — Do they lock rows in different orders?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

1062 — MySQL ERROR 1062 (23000): Duplicate entry for key (MySQL)10621213 — MySQL ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction (MySQL)12132006 — MySQL ERROR 2006 (HY000): MySQL server has gone away (MySQL)200625P02 — ERROR: current transaction is aborted, commands ignored until end of transaction block (PostgreSQL)25P0240001 — ERROR: could not serialize access due to concurrent update (PostgreSQL)40001Error acquiring the state lock — Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked (Terraform)Error acquiring the s…Lock wait timeout — Lock wait timeout exceeded; try restarting transaction (MySQL 1205) (SQL)Lock wait timeoutORA-00054 — ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired (SQL)ORA-00054Deadlock

Explore the map of this error Full error map →

🧠 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.