Re: About checking all dead lock tables - Mailing list pgsql-general

From Florian G. Pflug
Subject Re: About checking all dead lock tables
Date
Msg-id 443BE0BB.8030004@phlo.org
Whole thread Raw
In response to Re: About checking all dead lock tables  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
Michael Fuhr wrote:
> On Thu, Apr 06, 2006 at 03:36:33PM -0400, Emi Lu wrote:
>
>>How to check whether a table is locked?
> You can monitor locks by querying the pg_locks view.
>
> http://www.postgresql.org/docs/8.0/interactive/monitoring-locks.html
> http://www.postgresql.org/docs/8.0/interactive/view-pg-locks.html
>
> Only a few operations lock entire tables; for more information see
> the Concurrency Control chapter in the documentation.
>
> http://www.postgresql.org/docs/8.0/interactive/mvcc.html

>>Is there a way that I can find all deadlocks under postgresql 8.0.1 ?
> Are you sure you mean "deadlocks"?  Deadlock occurs when transaction
> A holds a lock that transaction B wants and transaction B holds a
> lock that transaction A wants; PostgreSQL detects this condition
> and aborts one of the transactions, allowing the other to continue.
> By default this happens after one second (see the deadlock_timeout
> setting).
>
> Perhaps you want to see pending or blocked lock attempts, i.e.,
> locks that have been requested but are not yet acquired because
> another transaction holds a conflicting lock.  If that's the case
> then look for rows in pg_locks where "granted" is false.

Note, however, that (badly programmed) clients can cause deadlocks which
postgres doesn't detect. This happend, for example, if you open more than
one connection to the same database from the same thread of a client app.
If a transaction on one connection waits for a transaction on another connection
to commit or rollback, you have effectivly deadlocked, because now your thread
is blocked, and the "other" transaction hasn't got a change to commit or rollback
anymore. But since postgres doesn't know about this interdependency between your
two connections, it won't report a deadlock.

greetings, Florian Pflug


pgsql-general by date:

Previous
From: Scott Ribe
Date:
Subject: Re: sound index
Next
From: Scott Ribe
Date:
Subject: Re: sound index