Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 767C7476A15 for ; Fri, 24 Jan 2003 03:24:13 -0500 (EST) Received: from web13808.mail.yahoo.com (web13808.mail.yahoo.com [216.136.175.18]) by postgresql.org (Postfix) with SMTP id 8823B476EA9 for ; Fri, 24 Jan 2003 02:58:53 -0500 (EST) Message-ID: <20030124075854.73319.qmail@web13808.mail.yahoo.com> Received: from [216.173.173.66] by web13808.mail.yahoo.com via HTTP; Thu, 23 Jan 2003 23:58:54 PST Date: Thu, 23 Jan 2003 23:58:54 -0800 (PST) From: Chris Gamache Reply-To: cgg007@yahoo.com Subject: Race condition w/ FIFO Queue reappears! To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/389 X-Sequence-Number: 11254 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 writes: >> I have a program that claims a row for itself >> my $processid = $$; >> my $sql_update = <> 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