Re: FIFO Queue Problems

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Chris Gamache <cgg007(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: FIFO Queue Problems
Date: 2002-11-01 16:54:07
Message-ID: 20021101165407.GA32463@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Fri, Nov 01, 2002 at 06:56:30 -0800,
Chris Gamache <cgg007(at)yahoo(dot)com> wrote:
>
> 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.

I played with this a bit and it looks like you want transaction isolation
level serializable and have the application retry when necessary.

Doing a select for update won't work cleanly. What will happen is that
you will get 0 rows returned when there is a conflict and you will need
to detect that same as you would by changing the isolation level.

What happens in the select for update case is you first rewrite the select
to use order by and limit to pick the minimum row since you can't use
for update when returning an aggregate. Then when the matching row is
found there is a possible lock contention with another update. If this
happens then when the other update commits the locked row is rechecked and
will no longer match and gets removed from the list of rows returned (leaving
no rows).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ken Guest 2002-11-01 17:07:43 Re: postgres on a FreeBSD 4.5 box
Previous Message Tom Lane 2002-11-01 16:51:48 Re: pg_restore error

Browse pgsql-sql by date

  From Date Subject
Next Message Charles H. Woloszynski 2002-11-01 18:26:57 HA PostgreSQL
Previous Message Tom Lane 2002-11-01 16:51:01 Re: FIFO Queue Problems