Thread: Logging deadlocked statements?

Logging deadlocked statements?

From
"Mason Hale"
Date:
We're noticing a number of deadlock errors in our postgres logs.
Along with the errors, there is a single statement logged to give
context to the deadlock.

Is is possible to log all the statements involved in the deadlock?
We're having a hard time detecting these deadlocks when they happen,
and it would help if we knew what other statements were involved.

I know about looking at the pg_locks table, and will do that if we can
catch one of these happening in real time. But I'm most interested in
knowing if I can somehow log all statements involved in a deadlock
when they occur. Is that possible?

thanks in advance,
Mason