postgres-errors-deadlocks
Installation
SKILL.md
postgres-errors-deadlocks
Quick Reference :
A deadlock is two or more transactions each holding a lock the other one needs : neither can proceed. PostgreSQL detects the cycle automatically and aborts one transaction (the victim) so the rest complete. The victim's session sees :
ERROR: deadlock detected -- SQLSTATE 40P01
DETAIL: Process 123 waits for ShareLock on transaction 456; blocked by process 789.
Process 789 waits for ShareLock on transaction 999; blocked by process 123.
HINT: See server log for query details.
A deadlock is NEVER a PostgreSQL bug. It is always the application acquiring locks in an inconsistent order across code paths. The two fixes :