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 8723256483 for ; Wed, 9 Mar 2005 16:12:51 +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 63454-06 for ; Wed, 9 Mar 2005 16:12:50 +0000 (GMT) Received: from webmail.muc.domeus.com (mail.ecircle.de [195.140.186.200]) by svr1.postgresql.org (Postfix) with ESMTP id 0D8BD56482 for ; Wed, 9 Mar 2005 16:12:49 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by webmail.muc.domeus.com (READY) with ESMTP id 5784011C20A; Wed, 9 Mar 2005 17:12:48 +0100 (CET) Received: from [192.168.1.110] (unknown [192.168.1.110]) by webmail.muc.domeus.com (READY) with ESMTP id 43C6A11C1FD; Wed, 9 Mar 2005 17:12:48 +0100 (CET) Subject: Re: java is locked when select for update From: Csaba Nagy To: Mican Bican Cc: Postgres JDBC In-Reply-To: <915cd38805030907545882333f@mail.gmail.com> References: <915cd3880503081437272e5cfb@mail.gmail.com> <915cd38805030907545882333f@mail.gmail.com> Content-Type: text/plain Message-Id: <1110384760.2838.56.camel@coppola.muc.ecircle.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Wed, 09 Mar 2005 17:12:40 +0100 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.057 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/88 X-Sequence-Number: 12480 Mican, This lock is probably due to the foreign key constraint handling of postgres. I bet you have a foreign key on the table you're inserting to, and the rows the 2 users are inserting point to the same parent row in the parent table. Postgres places an exclusive lock on the parent row when you insert a child row, that's why a second insert (attempting to place an exclusive lock on the same parent row) will have to wait until the first insert is committed. You can't really avoid the lock conflict, but you can minimize that by not making long transactions. It is a bad idea anyway to open a transaction and wait for user input to end it, it is much better to first collect all the data from the user and then execute the transaction in one sweep. HTH, Csaba. On Wed, 2005-03-09 at 16:54, Mican Bican wrote: > Hello, > > I use Postgresql 8.0.1 with java 5 and jdbc3 on windows xp. > > When I do a "select for update" a row.. and dont commit the statement > and when in this time an other user do also this. my java gui wait and > locked till the first user commit his statement.. my question is how > can I realize this with java.. for example why they are not a > SQLException or are Error like "an other user is updating this row"... > or can I say to java "dont wait" or "dont lock" when you make a select > for update and an other user before you make this.. > > thank you.. > > best regards > > Mican Bican > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match