From: | Chris Gamache <cgg007(at)yahoo(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | 7.3 LOCK TABLE problem |
Date: | 2003-01-27 16:20:21 |
Message-ID: | 20030127162021.98154.qmail@web13808.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Tom's suggested solution worked GREAT in 7.2.x ... I tried taking the plunge
into 7.3.1 tonight. In 7.3.1, when my FIFO queue program goes to grab a row,
TWO processes grab the same row, almost without fail. I even changed my locking
statement to the dreaded
LOCK TABLE fifo IN ACCESS EXCLUSIVE MODE;
it still exhibits the same behavior. I've tried variations on the theme, but I
can't seem to figure it out. I'm stumped!
The postgresql configuration is as identical (IMO) as I could possibly make it
considering the changes from 7.2 to 7.3. I can't imagine a config option would
control something so basic. I can't find any reference to it in the 7.3 docs,
and my tired eyes did not pick any fixes remotely pertaining to this type of
locking problem in the HISTORY file.
I'm (sadly) switching back to 7.2 until we can figure this out.
CG
>Chris Gamache <cgg007(at)yahoo(dot)com> writes:
>> 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
>> The problem occurrs when two of the processes grab the exact same row at the
>> exact same instant.
>
>Probably the best fix is to do it this way:
>
> BEGIN;
> LOCK TABLE fifo IN EXCLUSIVE MODE;
> UPDATE ... as above ...
> COMMIT;
>
>The exclusive lock will ensure that only one process claims a row
>at a time (while not preventing concurrent SELECTs from the table).
>This way you don't need to worry about retrying.
>
> regards, tom lane
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | juleni | 2003-01-27 16:46:42 | Function returns mutliple rows - HELP |
Previous Message | Mark Cave-Ayland | 2003-01-27 15:59:52 | Ref to last INSERT on a table without OIDs? |