Re: Basic locking question - Mailing list pgsql-general

From Tom Lane
Subject Re: Basic locking question
Date
Msg-id 21477.1126047992@sss.pgh.pa.us
Whole thread Raw
In response to Re: Basic locking question  (Ben <bench@silentmedia.com>)
Responses Re: Basic locking question
List pgsql-general
Ben <bench@silentmedia.com> writes:
> Doesn't select ... for update only lock the rows returned in the select?

Right.

> In my case, I'm worried about situations when no rows will be returned
> and two separate transactions will try to insert the same key.

Pretty much the only thing you can do about that is to take an exclusive
table-level lock.  This is simple but pretty awful for concurrency
(since the lock blocks everyone else from inserting ANY key, not only
the one you are inserting).

Consider using a sequence object to generate the keys, instead.

            regards, tom lane

pgsql-general by date:

Previous
From: Ben
Date:
Subject: Re: Basic locking question
Next
From: Ben
Date:
Subject: Re: Basic locking question