Re: how do i avoid multiple sessions from inserting the - Mailing list pgsql-general

From Tom Lane
Subject Re: how do i avoid multiple sessions from inserting the
Date
Msg-id 10225.1046184190@sss.pgh.pa.us
Whole thread Raw
In response to Re: how do i avoid multiple sessions from inserting the  (Kolus Maximiliano <Kolus.maximiliano@bcr.com.ar>)
List pgsql-general
Kolus Maximiliano <Kolus.maximiliano@bcr.com.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

pgsql-general by date:

Previous
From: Andrew Perrin
Date:
Subject: Re: Can postgresql be run in memory (like a memory resident
Next
From: Ericson Smith
Date:
Subject: Re: 7.4?