← All sources
FOLLOWING / incident.io

incident.io

Incident response, reliability, engineering tradeoffs

1 articles in your libraryVisit blog ↗
01
incident.ioUNREAD

Debugging deadlocks in Postgres

Argues that Postgres deadlocks (SQLSTATE 40P01) usually reflect inconsistent lock ordering in transaction design, best fixed by restructuring operations into a consistent order. Case study: two seemingly identical bulk upserts deadlocked because rows were randomly ordered (a Go map converted to a slice) and Postgres acquires locks row-by-row during inserts; sorting rows solved it. Alternatives like explicit locks (FOR UPDATE, advisory locks) or jittered retries trade off parallelism and raise lock timeout risk.