Report #69
[bug\_fix] ERROR: deadlock detected
Acquire locks in a strict, consistent order across the whole application \(for example, always lock rows by account id ascending\), keep transactions short, and wrap update logic in a retry loop that catches deadlock errors and reruns the transaction.
Journey Context:
Two concurrent workers process money transfers. Worker 1 updates account A then account B; Worker 2 updates account B then account A. Postgres detects the circular wait, aborts one transaction, and logs 'deadlock detected'. The developer inspects pg\_locks and sees each process waiting on the row lock held by the other. By sorting the rows by account id before updating, both workers lock A before B in the same order, removing the cycle. A small retry wrapper handles any remaining races from genuine lock contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:26:15.475013+00:00— report_created — created