X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EA7F13A41E0 for ; Mon, 22 Nov 2004 06:24:29 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93939-05 for ; Mon, 22 Nov 2004 06:24:19 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id C30C03A5103 for ; Mon, 22 Nov 2004 06:24:18 +0000 (GMT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CW7cT-0001P6-00; Mon, 22 Nov 2004 19:24:13 +1300 Message-ID: <41A1870F.4030506@opencloud.com> Date: Mon, 22 Nov 2004 19:28:31 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.9 (X11/20041115) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Temp02 Cc: pgsql-jdbc@postgresql.org Subject: Re: Can't throw the dreaded 'idle in transaction' - need help! References: <02fe01c4d054$b60a5fe0$2201010a@bluereef.local> In-Reply-To: <02fe01c4d054$b60a5fe0$2201010a@bluereef.local> X-Enigmail-Version: 0.86.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/167 X-Sequence-Number: 11589 Temp02 wrote: > 1. We don't know how we can find out exactly which statement caused the > idle-in-transaction, all we know is which is waiting for the row via > pg_stat_activity. How can we find this information? You might want to turn on statement logging on the DB side. Once you identify the row that is locked, you should be able to backtrack through the logs and find a connection that locked that row but has not subsequently committed or rolled back. Note that there is no query that "causes" idle-in-transaction. The connection is *idle*; it is not processing a query. > 2. Is the idle in transaction a "normal" event for all update > transactions? It doesn't really have anything to do with update transactions; it's just that you only see problems if it is an update transaction that goes idle, as it will be holding locks. Idle in transaction just means that the connection is in a transaction (at the JDBC level, autocommit is off and a query has been issued) and the backend is waiting for a new query to arrive. > Should the database release the lock immediately after the > commit, in all instances? Yes. > Should we assume that when we see an 'idle in > transaction' that some error event has occurred that we're not seeing, > like a failed query etc, that's causing the connection to remain open? The usual cause is that your application is not closing (via commit/rollback) a transaction it has started. There are many possible reasons for this, but failing to deal with errors is a common one. I'd suggest checking your application code to make sure that transactions are always closed, even in the face of exceptions or other failures. Alternatively, you might have an application/db deadlock happening (thread 1 acquires DB lock; thread 2 acquires Java lock; thread 1 blocks waiting for thread 2 to release the Java lock; thread 2 blocks waiting for the transaction started by thread 1 to complete and release the DB lock; everything stops). Sending the JVM a SIGQUIT (causing a thread dump) might help if the responsible thread really is blocked and hasn't just leaked the connection or forgotten to close the transaction. -O