Re: java is locked when select for update

From: Csaba Nagy <nagy(at)ecircle-ag(dot)com>
To: Mican Bican <mican58(at)gmail(dot)com>
Cc: Postgres JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: java is locked when select for update
Date: 2005-03-09 16:12:40
Message-ID: 1110384760.2838.56.camel@coppola.muc.ecircle.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geoffrey 2005-03-09 16:28:05 Re: PostgreSQL still for Linux only?
Previous Message Mican Bican 2005-03-09 15:54:40 java is locked when select for update

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2005-03-09 16:28:45 Re: java is locked when select for update
Previous Message Rover, Mischa de 2005-03-09 16:10:55 Crystal Reports: Connection rejected: FATAL: no PostgreSQL user name specified in startup packet.