Here is my understanding of how deadlock_timeout
behaves in postgres - am I correct?
deadlock_timeout
is a setting on transaction level, it can be changed via set local
, so each transaction runs the 'deadlock detection logic' by itself and there is no such logic on a level higher than on transaction leveldeadlock_timeout
seconds whether it is now in a deadlock situationThat is mostly correct. The timer for the deadlock check is set only once. If there is no deadlock after deadlock_timeout
, there will be no more check for deadlocks. That is correct, because the only way that we could get into a deadlock later on is if another backend gets stuck behind a lock as well. Then that backend's deadlock check will detect and resolve the problem.
See the functions DeadLockCheck()
and CheckDeadLock()
in the source code.