pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Gamache <cgg007@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: FIFO Queue Problems
Date: Fri, 1 Nov 2002 06:56:30 -0800 (PST)
Message-ID: <20021101145630.50886.qmail@web13801.mail.yahoo.com> (raw)
In-Reply-To: <20021101143348.A7426@goldfisch.at>

I'm having a race condition with a FIFO queue program that I've created...

CREATE TABLE fifo (
  id serial,
  data varchar(100),
  status int4 DEFAULT 0
);

I have a program that claims a row for itself

  my $processid = $$;
  my $sql_update = <<EOS;
    UPDATE fifo
      set status=$processid
    WHERE id = (SELECT min(id) FROM fifo WHERE status=0);
EOS

I can then

  my $sql_get = <<EOS
    SELECT data FROM fifo WHERE status=$processid
EOS

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?


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/



view thread (7+ messages)  latest in thread

Message-ID: <20021101145630.50886.qmail@web13801.mail.yahoo.com>
Permalink:  ../20021101145630.50886.qmail@web13801.mail.yahoo.com/
Also on:    postgresql.org/message-id/20021101145630.50886.qmail@web13801.mail.yahoo.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: cgg007@yahoo.com
  Subject: Re: FIFO Queue Problems
  In-Reply-To: <20021101145630.50886.qmail@web13801.mail.yahoo.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