pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: John R Pierce <pierce@hogranch.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: "Idle in Transaction" revisited.
Date: Fri, 17 Sep 2004 19:40:31 -0400
Message-ID: <26344.1095464431@sss.pgh.pa.us> (raw)
In-Reply-To: <0dfb01c49d0e$5c61c1f0$0200a8c0@hogranch.com>
References: <0dfb01c49d0e$5c61c1f0$0200a8c0@hogranch.com>

"John R Pierce" <pierce@hogranch.com> writes:
> We've been running into a *lot* of problems with "Idle in Transaction" 
> threads causing long term blockage of VACUUM's ability to free up dead rows. 

Yeah, that's from prematurely issuing BEGIN.  I believe there's a
solution for this in the most recent JDBC driver versions --- but
I dunno if it's in any official releases yet.

> One case in point, as a SQL form of 'mutex', one of these developers was 
> used to doing a 'UPDATE' on a particular row of a table without ever 
> committing to leave a row lock in place so that other threads won't attempt 
> to 'subscribe' to the same 'topic' on a corporate intranet messaging system. 
> We can't do this in Postgres (works great in Oracle) due to the 'idle in 
> transaction' issue...

Check.  It seems like what you might want here is cooperative locking
a la the contrib/userlock module.  We were just having a discussion in
another list about whether that code had any real future ... but if we
see people actually using it in the field, it's much more likely to get
moved into the mainline than dropped.

> What about a resource locking table like I described above, where we've got 
> a few dozen arbitrarily named resources we need to gain a mutex on?   When I 
> suggested 'select for update' to see if the resource was available, then 
> 'update' to mark it in use, and commit, the developer said that leaves the 
> resource locked if the app crashes or the box is rebooted or whatever, while 
> his row lock would be cleared automatically.

A userlock will be dropped on session exit or database restart, so I
think that base is covered.  The main objection I can think of is that
it is voluntary, since the backend has no idea what other DB resources
a userlock is meant to protect.  Depending on your coding practices that
might be fine, or it might be a fatal drawback.

If you migrate to using userlocks or some variant, let us know --- real
applications using it will definitely move that code way up in priority.

			regards, tom lane



view thread (28+ messages)  latest in thread

Message-ID: <26344.1095464431@sss.pgh.pa.us>
Permalink:  ../26344.1095464431@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26344.1095464431@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, pierce@hogranch.com
  Subject: Re: "Idle in Transaction" revisited.
  In-Reply-To: <26344.1095464431@sss.pgh.pa.us>
  References: <0dfb01c49d0e$5c61c1f0$0200a8c0@hogranch.com> <26344.1095464431@sss.pgh.pa.us>

* 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