ERROR 40P01 deadlock detected; one transaction aborts.
Two transactions each hold a lock the other needs.
tail -100 /var/log/postgresql/*.log | grep -A4 deadlockUPDATE ... WHERE id IN (SELECT id FROM t ORDER BY id FOR UPDATE)BEGIN late, COMMIT early; no user waits inside a txnLock ordering conventions + statement timeouts (lock_timeout 5s).
Spinning up a fresh box to reproduce or escape this error?
Managed cloud hostingNinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.
Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog