Dev Tools · 1h ago
Postgres Deadlock Detection: Why Retry Loops Make Things Worse
Postgres detects deadlocks by building a wait-for graph only after a backend waits longer than deadlock_timeout (default 1s). It aborts one transaction to break the cycle, but retrying blindly without fixing lock order causes repeated deadlocks, flooding logs and burning CPU on graph algorithms. The deadlocks counter in pg_stat_database increments each time, but no history view exists—logs must be scraped.
Meridian48 take
The article correctly warns that naive retry logic amplifies deadlock damage, but it understates how often application-level lock ordering fixes are ignored in favor of quick retry patches.
postgresdeadlock-detection