Thursday, 19 September 2013

PostgreSQL concurent update selects

PostgreSQL concurent update selects

I am attempting to have some sort of update select for a job queue. I need
it to support concurrent processes affecting the same table or database
This server will be used only for the queue so a database per queue is
acceptable. Orginally I was thinking about something like the following:
UPDATE state=1,ts=NOW() FROM queue WHERE ID IN (SELECT ID FROM queue WHERE
state=0 LIMIT X) RETURN *
Which I been reading that this will cause a race condition, I read that
there was a an option for the SELECT subquery to use FOR UPDATE, but then
that will lock the row and concurrent calls will be blocked where I would
not mind if they skip over to the next unlocked row.
So what i am asking for is the best way to have a fifo system in postgres
that requires the least amount of locking the entire database.

No comments:

Post a Comment