blocking INSERTs - Mailing list pgsql-general

From Joseph Shraibman
Subject blocking INSERTs
Date
Msg-id 42A666AA.70608@selectacast.net
Whole thread Raw
Responses Re: blocking INSERTs  (Douglas McNaught <doug@mcnaught.org>)
Re: blocking INSERTs  (Dennis Bjorklund <db@zigo.dhs.org>)
Re: blocking INSERTs  (Csaba Nagy <nagy@ecircle-ag.com>)
List pgsql-general
I want to do the following:

BEGIN;
SELECT ... FROM table WHERE a = 1 FOR UPDATE;
UPDATE table SET ... WHERE a = 1;
if that resturns zero then
INSERT INTO table (...) VALUES (...);
END;

The problem is that I need to avoid race conditions.  Sometimes I get
primary key exceptions on the INSERT.

I think I need to lock the table in share mode to keep inserts from
happening, but that blocks vacuums, and blocked vacuums block other
things behind them.  So how do I get around this?

pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: To SPAM or not to SPAM...
Next
From: Douglas McNaught
Date:
Subject: Re: blocking INSERTs