pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Carr <joe.carr@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Correct usage of FOR UPDATE?
Date: Thu, 9 Dec 2010 14:29:42 -0500
Message-ID: <AANLkTin1qX+ZSOGsvdY7RH0dkTEkxth-XaAy2DSA8HTd@mail.gmail.com> (raw)

Hello,
I have a simple table-based queue system, and I'd looking for some advice on
improving my dequeue function. it boils down to:

SELECT id
FROM queue
WHERE <whereclause>
FOR UPDATE NOWAIT;

which works well, in that no item gets dequeued more that once. The issue,
however is that when a contention occurs, the error "could not obtain lock
on row in relation" is raised.

Is there a way that I can rewrite this so that when a contention occurs,
there is no error? I would like the "winning" process to lock the row, and
the "losing" process to select null rather than raise the rowlock error.

thanks beforehand for any help!

view thread (2+ messages)  latest in thread

Message-ID: <AANLkTin1qX+ZSOGsvdY7RH0dkTEkxth-XaAy2DSA8HTd@mail.gmail.com>
Permalink:  ../AANLkTin1qX+ZSOGsvdY7RH0dkTEkxth-XaAy2DSA8HTd@mail.gmail.com/
Also on:    postgresql.org/message-id/AANLkTin1qX+ZSOGsvdY7RH0dkTEkxth-XaAy2DSA8HTd@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: joe.carr@gmail.com
  Subject: Re: Correct usage of FOR UPDATE?
  In-Reply-To: <AANLkTin1qX+ZSOGsvdY7RH0dkTEkxth-XaAy2DSA8HTd@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox