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 09B9C329E4C for ; Sat, 18 Sep 2004 00:40:37 +0100 (BST) 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 52330-08 for ; Fri, 17 Sep 2004 23:40:30 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4BF10329D7A for ; Sat, 18 Sep 2004 00:40:32 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8HNeVJ9026345; Fri, 17 Sep 2004 19:40:31 -0400 (EDT) To: "John R Pierce" Cc: pgsql-jdbc@postgresql.org Subject: Re: "Idle in Transaction" revisited. In-reply-to: <0dfb01c49d0e$5c61c1f0$0200a8c0@hogranch.com> References: <0dfb01c49d0e$5c61c1f0$0200a8c0@hogranch.com> Comments: In-reply-to "John R Pierce" message dated "Fri, 17 Sep 2004 16:30:47 -0700" Date: Fri, 17 Sep 2004 19:40:31 -0400 Message-ID: <26344.1095464431@sss.pgh.pa.us> From: Tom Lane 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: 200409/90 X-Sequence-Number: 10980 "John R Pierce" 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