SECURITY WARNING: Never run commands you don't understand. Always review code before execution. Use at your own risk.
Database 41 errors

Database Errors

Connections, deadlocks, constraints, replication and memory limits.

Understanding Database errors

Database errors group into connection exhaustion, lock contention and deadlocks, constraint violations, and resource limits. Connection errors under load are the most misdiagnosed: "too many connections" is almost never fixed by raising max_connections, because each connection costs memory. It is fixed by putting a pooler in front and finding the code path that leaks connections.

How to debug Database errors

  1. Look at what the server currently sees: SELECT * FROM pg_stat_activity in PostgreSQL, SHOW FULL PROCESSLIST in MySQL. Sessions sitting in idle in transaction are the usual culprit behind connection exhaustion.
  2. For deadlocks, read the deadlock report the database logs. It names both transactions and the exact lock order. The fix is nearly always to make all code paths acquire locks in the same order.
  3. Check whether the error is from the database or from a pooler. PgBouncer, ProxySQL and RDS Proxy return their own errors that look database-native but need pooler-side fixes.
  4. Run EXPLAIN (ANALYZE, BUFFERS) on slow queries. Lock-wait timeouts are often just very slow queries holding locks longer than they should.
  5. Verify you are connected to the writer, not a read replica. READONLY and "cannot execute in a read-only transaction" errors mean traffic is reaching the wrong endpoint.

Tools worth reaching for

  • pg_stat_activity
  • SHOW ENGINE INNODB STATUS
  • EXPLAIN ANALYZE
  • slow query log
  • pgbadger

All 41 Database errors

Other categories