pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Mican Bican <mican58@gmail.com>
Cc: jdbc mailinglist <pgsql-jdbc@postgresql.org>
Subject: Re: lock problem when dont commit
Date: Thu, 03 Mar 2005 07:19:39 -0500
Message-ID: <422700DB.1050503@fastcrypt.com> (raw)
In-Reply-To: <4226C7C4.6020002@gmail.com>
References: <915cd3880503021437382b001e@mail.gmail.com>
	<42264B3F.4080409@fastcrypt.com>
	<15017.1109806796@sss.pgh.pa.us>
	<42265BA3.7030509@fastcrypt.com>
	<15716.1109813069@sss.pgh.pa.us>
	<4226C7C4.6020002@gmail.com>

As Tom pointed out this behaviour will not change in the immediate 
future.  I think your best bet is not to hold the lock for so long.

I generally prepare all the data and do the insert in one statement.

Dave

Mican Bican wrote:

> Tom Lane schrieb:
>
>> Dave Cramer <pg@fastcrypt.com> writes:
>>  
>>
>>> Tom Lane wrote:
>>>   
>>>
>>>> Maybe a conflict on referenced foreign-key rows?
>>>>     
>>>
>>
>>  
>>
>>> can you explain how that happens?
>>>   
>>
>>
>> When you insert or update a row in a table that has an FK reference,
>> it takes out a row-level lock on the referenced row in the master table.
>> This is needed to prevent someone else from deleting the master row
>> before commit.  (Since the someone else can't see your uncommitted row,
>> nothing but a lock could stop them from thinking it's OK to remove the
>> master row.)
>>
>> So if two sessions are trying to insert rows that reference the same
>> master row, they conflict --- because the only type of row-level lock
>> we have at the moment is exclusive.  I believe Alvaro is looking into
>> supporting shared row-level locks for 8.1, which'd make this problem
>> go away.
>>
>>             regards, tom lane
>>
>>  
>>
> Ok I think thats the problem.. because
>
> client1:
>
> ...
> conn.setAutoCommit(false)
> insert into liefAdress(adress,postcode) //id is autoincrement insert 
> into liefAdress(adress2,postcode2)
> ....
> ....
>
>
> postcode is a FK to a list with postcodes. When I want insert different
> postcodes they are no locked.. there is only locked when the postcode are
> same. But why there are locked? Have anybody a good
> Idea to deal with this problem..?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>
>

-- 
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561




view thread (7+ messages)

Message-ID: <422700DB.1050503@fastcrypt.com>
Permalink:  ../422700DB.1050503@fastcrypt.com/
Also on:    postgresql.org/message-id/422700DB.1050503@fastcrypt.com

 · 

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: pg@fastcrypt.com, mican58@gmail.com
  Subject: Re: lock problem when dont commit
  In-Reply-To: <422700DB.1050503@fastcrypt.com>
  References: <915cd3880503021437382b001e@mail.gmail.com> <42264B3F.4080409@fastcrypt.com> <15017.1109806796@sss.pgh.pa.us> <42265BA3.7030509@fastcrypt.com> <15716.1109813069@sss.pgh.pa.us> <4226C7C4.6020002@gmail.com> <422700DB.1050503@fastcrypt.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