Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CF721476E52 for ; Fri, 1 Nov 2002 14:18:56 -0500 (EST) Received: from mta5.snet.net (mta5.snet.net [204.60.203.77]) by postgresql.org (Postfix) with ESMTP id 573464761EA for ; Fri, 1 Nov 2002 14:18:41 -0500 (EST) Received: from pop.snet.net (pop.snet.net [204.60.203.72]) by mta5.snet.net (8.12.3/8.12.3/SNET-mx-1.2/D-1.1.1.1/O-1.1.1.1) with ESMTP id gA1JFQu2022819 for ; Fri, 1 Nov 2002 14:15:26 -0500 (EST) X-Originating-IP: [64.252.95.167] X-SBCIS-MTA: [pop.snet.net] Received: from [192.168.1.83] (167.95.252.64.snet.net [64.252.95.167]) by pop.snet.net (8.12.3/8.12.3/SNET-pop-1.2/D-1.1.1.1/O-1.1.1.1) with ESMTP id gA1JIRH8007926 for ; Fri, 1 Nov 2002 14:18:27 -0500 (EST) Subject: Re: FIFO Queue Problems From: Wei Weng To: pgsql-sql@postgresql.org In-Reply-To: <26900.1036169461@sss.pgh.pa.us> References: <20021101145630.50886.qmail@web13801.mail.yahoo.com> <26900.1036169461@sss.pgh.pa.us> Content-Type: text/plain Organization: Message-Id: <1036178317.23296.2.camel@Monet> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.1.90 (Preview Release) Date: 01 Nov 2002 14:18:37 -0500 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/15 X-Sequence-Number: 10157 Do you need to unlock the table fifo when you are done? On Fri, 2002-11-01 at 11:51, Tom Lane wrote: > 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org -- Wei Weng