PostgreSQLDeadlockConflicts¶
| Severity | warning |
| Fires when | A database has more than 10 deadlocks, for 5 minutes |
What it means¶
PostgreSQL has found more than 10 deadlocks in a database. A deadlock happens
when two transactions wait for each other: each one holds a lock that the other
one needs. PostgreSQL detects this and stops one of the transactions with the
error deadlock detected (SQLSTATE 40P01).
Note
The alert uses the total number of deadlocks since the statistics of the database were last reset. It can keep firing after you have fixed the cause. In this case, mute the alert and contact support.
What happens if you do nothing¶
The database keeps working. Each deadlock makes one transaction fail, and your application gets an error. If the application does not retry, the change of this transaction is lost.
What to do¶
-
Check which database has the deadlocks:
-
Check the logs for
deadlock detected. PostgreSQL logs the processes, the locks, and the queries that were part of the deadlock. See View Logs. - Fix the application with the queries from the log:
- Change rows and tables in the same order in all transactions.
- Keep transactions short.
- Lock the rows you want to change at the start of the transaction, for
example with
SELECT ... FOR UPDATE, in a fixed order. - Retry a transaction that fails with SQLSTATE
40P01.