X-Original-To: pgsql-general-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A7A0C9FB2E8 for ; Sun, 10 Sep 2006 09:21:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 84467-10 for ; Sun, 10 Sep 2006 09:21:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id C7AB69FB305 for ; Sun, 10 Sep 2006 09:21:05 -0300 (ADT) Received: (qmail 20093 invoked from network); 10 Sep 2006 12:21:04 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.2?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 10 Sep 2006 12:21:04 -0000 In-Reply-To: <450390B5.1000801@geophile.com> References: <4503046F.7030901@Berghold.Net> <22969.1157849374@sss.pgh.pa.us> <450390B5.1000801@geophile.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <6C383267-9302-4D8B-88DA-B3EF444AEFFF@fastcrypt.com> Cc: General , pgsql-jdbc@postgresql.org, Tom Lane , Peter@berghold.net Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: [JDBC] Idle in transaction state. Date: Sun, 10 Sep 2006 08:21:02 -0400 To: Jack Orenstein X-Mailer: Apple Mail (2.752.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.036 tagged_above=0 required=5 tests=AWL, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/377 X-Sequence-Number: 100631 On 10-Sep-06, at 12:12 AM, Jack Orenstein wrote: > Tom Lane wrote: >> "Peter L. Berghold" writes: >>> What I'm seeing is the first time my web application is being run >>> there >>> is a bunch of processes running around that look like: >>> "postgres: peter peter_trialdb 127.0.0.1(46222) idle" >> "idle" is fine, "idle in transaction" is not so fine, because those >> might be holding locks that block things like schema changes. You >> need >> to figure out why your client-side code isn't closing out its >> transactions promptly. >> You'd probably be better off asking on the pgsql-jdbc list about >> this, >> as the folks likely to know about Java-stack issues hang out there. > > I haven't seen the discussion show up on the JDBC list so I'll post > to both lists. > > I noticed the same problem in my JDBC/postgresql application. My > application does Connection.setAutoCommit(false) for every connection; > connections were kept in a home-grown connection pool. > > I began to suspect that turning off auto-commit was resulting in "idle > in transaction" processes, and also causing VACUUM to reclaim fewer > tuple versions than I thought it should be reclaiming. This was true > even though my application always either commits or aborts before > returning the connection to the pool. > > Now what I do is setAutoCommit(true) after the commit or abort, and > before returning the connection to the pool. Then, on taking a > connection from the pool, I setAutoCommit(false). This seems to have > solved both problems. I don't really understand why this works, > however. I would expect the commit or abort to suffice. > > (I can post a test program demonstrating the problem if there is > interest.) Pools should set autocommit to true upon close(). Since pools wrap close() the driver has no way to deal with being put back into a pool and left idling in a transaction. Dave > > Jack Orenstein > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >