Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id B6D12632D27 for ; Thu, 31 Dec 2009 00:28:49 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 79214-06 for ; Thu, 31 Dec 2009 04:28:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f176.google.com (mail-iw0-f176.google.com [209.85.223.176]) by mail.postgresql.org (Postfix) with ESMTP id B45A9632454 for ; Thu, 31 Dec 2009 00:28:38 -0400 (AST) Received: by iwn6 with SMTP id 6so8279461iwn.15 for ; Wed, 30 Dec 2009 20:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=ZftomVAPh6ewE4kfgZjcc+vXx3xeyRAtLsNkE3Mo6Ck=; b=Ly5lgWhzL2rF7dHR3eKIGBVRFfwLn6LcF/wJusLh9cm602t3DpOWJtTsDkFG1yXOei ZT+H6rd78LU8lV69eH76jQfLscFuhko7m+koEB0RpGzQ0Sxuxj7V508qoUqThrrBW3X6 jumqIYbzle06Y302C1LnUGQpbAKeunjgI5bWg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=rMGMiRi14dAy4Clrxx6fme2aNfv5dH06bjT5BW5PyoGUC8/1bs+XPEqCU/qD3E1rxS g2ZKuKu8/41YGzsFl213YRB5libHHfT7GdDHy65qfx4TYFmY5tp60FqeGSiHK+qkN+RU f4VWWcs9GcuSrxxhfZxykTuEfiKjECPbUNvhY= MIME-Version: 1.0 Received: by 10.231.59.129 with SMTP id l1mr2430071ibh.0.1262233717416; Wed, 30 Dec 2009 20:28:37 -0800 (PST) In-Reply-To: <4B3BF93A.50108@postnewspapers.com.au> References: <16cfd0b20912300829s47e5b081ma318561897d8d1bf@mail.gmail.com> <4B3BF93A.50108@postnewspapers.com.au> Date: Thu, 31 Dec 2009 09:58:37 +0530 Message-ID: <16cfd0b20912302028v3e1ef1e7g3a81d43067ee2634@mail.gmail.com> Subject: Re: locking problem in jdbc driver? From: Sherif Kottapurath To: Craig Ringer Cc: pgsql-jdbc@postgresql.org Content-Type: multipart/alternative; boundary=00163646d9a159a59a047bfeb0e7 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.598 tagged_above=-10 required=5 tests=BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200912/115 X-Sequence-Number: 20196 --00163646d9a159a59a047bfeb0e7 Content-Type: text/plain; charset=UTF-8 On Thu, Dec 31, 2009 at 6:37 AM, Craig Ringer 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 > --00163646d9a159a59a047bfeb0e7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 =C2=A0lock=
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 th= e
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 conn= ection while another one is using it, it will wait until the other thread h= as finished its current operation. If the operation is a regular SQL =C2=A0= statement, then the operation consists of sending the statement and retriev= ing any ResultSet (in full)."

The lock your thread is waiting on is a lock that controls access to the Po= stgreSQL 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 connec= tion)
around threads, and that must be the culprit. Should be able to report back= within a day whether that was indeed the culprit.

=C2=A0
<= blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 2= 04, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> If your threads are deadlocking, it's probably because one thread is w= aiting for another to do work that it cannot do until the first thread rele= ases 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 ea= ch waiting for locks the other connection holds. You're only using one = connection, and your issue is with Java locking, so PostgreSQL knows nothin= g about it.


We are using multiple connections, but apparently= , sometimes 2 threads are trying to use the same connection
and one of t= hese threads is also holding another incomplete transaction.

Thanks = a lot.

Sherif

--
Craig Ringer

--00163646d9a159a59a047bfeb0e7--