Re: FIFO Queue Problems

From: Richard Huxton <dev(at)archonet(dot)com>
To: cgg007(at)yahoo(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: FIFO Queue Problems
Date: 2002-11-01 16:20:59
Message-ID: 200211011620.59439.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Friday 01 Nov 2002 2:56 pm, Chris Gamache wrote:
> I'm having a race condition with a FIFO queue program that I've created...

> I have a program that claims a row for itself

[code sample]

> The problem occurrs when two of the processes grab the exact same row at
> the exact same instant. It happens roughly 1 out of 1000 times. I'm not
> sure if setting the transactions to serializable would fix the problem
> since it occurrs between different postmasters.
>
> My experience with Views and Triggers is minimal. Would they even help?
> Could someone suggest a better FIFO queue method?

Check out SELECT FOR UPDATE - this locks the row and should do what you want.
This means that 1 time in 1000 your query will fail and need to be retried.

HTH
--
Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Wood 2002-11-01 16:22:42 Re: postgres on a FreeBSD 4.5 box
Previous Message Richard Huxton 2002-11-01 16:17:39 Re: Questions on specifying table relationships

Browse pgsql-sql by date

  From Date Subject
Next Message Ross J. Reedstrom 2002-11-01 16:37:35 Re: Selecting * from the base table but getting the inheriteds
Previous Message Tim Perdue 2002-11-01 16:02:00 Re: Different size in the DATA directory