From: Jack Orenstein <jao@geophile.com>
To: General <pgsql-general@postgresql.org>
To: pgsql-jdbc@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter@berghold.net
Subject: Re: Idle in transaction state.
Date: Sun, 10 Sep 2006 00:12:37 -0400
Message-ID: <450390B5.1000801@geophile.com> (raw)
In-Reply-To: <22969.1157849374@sss.pgh.pa.us>
References: <4503046F.7030901@Berghold.Net>
<22969.1157849374@sss.pgh.pa.us>
Tom Lane wrote:
> "Peter L. Berghold" <Peter@berghold.net> 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.)
Jack Orenstein
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: jao@geophile.com, pgsql-general@postgresql.org, tgl@sss.pgh.pa.us, Peter@berghold.net
Subject: Re: Idle in transaction state.
In-Reply-To: <450390B5.1000801@geophile.com>
References: <4503046F.7030901@Berghold.Net> <22969.1157849374@sss.pgh.pa.us> <450390B5.1000801@geophile.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