pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sherif Kottapurath <sherifkm@gmail.com>
To: Craig Ringer <craig@postnewspapers.com.au>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: locking problem in jdbc driver?
Date: Thu, 31 Dec 2009 09:58:37 +0530
Message-ID: <16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com> (raw)
In-Reply-To: <4B3BF93A.50108@postnewspapers.com.au>
References: <16cfd0b20912300829s47e5b081ma318561897d8d1bf@mail.gmail.com>
	<4B3BF93A.50108@postnewspapers.com.au>

On Thu, Dec 31, 2009 at 6:37 AM, Craig Ringer
<craig@postnewspapers.com.au>wrote:

> On 31/12/2009 12:29 AM, Sherif Kottapurath wrote:
>
>> I am seeing the following problem, where a thread holding a java  lock
>> seems to be blocking another query. I suspect the the thread holding the
>> java lock
>> may be waiting for a DB lock to be freed by the second one. I am pasting
>> the
>> relevant parts of the java stack trace. All threads shown here are
>> operating on
>> the same table, and they are all parts of transactions involving
>> multiple tables.
>>
>
> It looks like your threads may all be trying to use the same connection.
>
> The PgJDBC documentation states: "If a thread attempts to use the
> connection while another one is using it, it will wait until the other
> thread has finished its current operation. If the operation is a regular SQL
>  statement, then the operation consists of sending the statement and
> retrieving any ResultSet (in full)."
>
> The lock your thread is waiting on is a lock that controls access to the
> PostgreSQL connection object so that only one thread may do work with it at
> a time.


Thanks Craig. This has set us off in the right direction. There is some code
which passes transactions (and related connection)
around threads, and that must be the culprit. Should be able to report back
within a day whether that was indeed the culprit.



> If your threads are deadlocking, it's probably because one thread is
> waiting for another to do work that it cannot do until the first thread
> releases the connection. Perhaps you forgot to close a statement somewhere?
>
>
>  deadlock detection is set for 1 sec and no dedlocks are reported by
>> postgres.
>>
>
> PostgreSQL will detect deadlocks where two connections in PostgreSQL are
> each waiting for locks the other connection holds. You're only using one
> connection, and your issue is with Java locking, so PostgreSQL knows nothing
> about it.
>
>
We are using multiple connections, but apparently, sometimes 2 threads are
trying to use the same connection
and one of these threads is also holding another incomplete transaction.

Thanks a lot.

Sherif

--
> Craig Ringer
>

view thread (5+ messages)

Message-ID: <16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com>
Permalink:  ../16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com/
Also on:    postgresql.org/message-id/16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: sherifkm@gmail.com, craig@postnewspapers.com.au
  Subject: Re: locking problem in jdbc driver?
  In-Reply-To: <16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com>
  References: <16cfd0b20912300829s47e5b081ma318561897d8d1bf@mail.gmail.com> <4B3BF93A.50108@postnewspapers.com.au> <16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox