Re: how do i avoid multiple sessions from inserting the

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kolus Maximiliano <Kolus(dot)maximiliano(at)bcr(dot)com(dot)ar>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how do i avoid multiple sessions from inserting the
Date: 2003-02-25 14:43:10
Message-ID: 10225.1046184190@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Kolus Maximiliano <Kolus(dot)maximiliano(at)bcr(dot)com(dot)ar> writes:
> I tried something slightly different:
> * LOCK the table in SHARE ROW EXCLUSIVE mode,

Well, sure, if you don't mind giving up concurrency of writers completely.
How likely is a conflict, anyway? If it's very probable then you're not
losing much, but if it's not then this isn't a good approach.

> * If i use LOCK TABLE users IN SHARE ROW EXCLUSIVE MODE in two psql session
> it works (one session gets the lock, the other waits). But inside the
> function it seems to be ignored (i had the dup key problem).

Within a function the snapshot doesn't get updated, so you cannot see
results of other transactions that commit after the function starts.
This means you pretty much have to issue the LOCK as a separate
interactive command.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Berend Tober 2003-02-25 14:51:49 Duplicated foreign key constraints
Previous Message Ericson Smith 2003-02-25 14:41:13 Re: 7.4?