Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 9D6F1632AC5 for ; Mon, 14 Jun 2010 10:59:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 80927-09 for ; Mon, 14 Jun 2010 13:59:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (vcs5.camavision.com [63.228.164.252]) by mail.postgresql.org (Postfix) with ESMTP id 8435E632521 for ; Mon, 14 Jun 2010 10:59:43 -0300 (ADT) Received: from [192.168.1.103] (173-20-246-8.client.mchsi.com [173.20.246.8]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id 9522359A49; Mon, 14 Jun 2010 08:59:41 -0500 (CDT) Message-ID: <4C1635CC.8060801@squeakycode.net> Date: Mon, 14 Jun 2010 08:59:40 -0500 From: Andy Colson User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100317 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: Elias Ghanem , pgsql-performance@postgresql.org Subject: Re: Dead lock References: <4C161793.2090105@acteos.com> In-Reply-To: <4C161793.2090105@acteos.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.001 tagged_above=-10 required=5 tests=BAYES_40=-0.001 X-Spam-Level: X-Archive-Number: 201006/246 X-Sequence-Number: 39102 On 06/14/2010 06:50 AM, Elias Ghanem wrote: > Hi all, > I have 2 data bases trying to perform an update query at the same time > on a same table in a third data base using db link. > I'm getting a dead lock exception: > ERROR: deadlock detected > DETAIL: Process 27305 waits for ShareLock on transaction 55575; blocked > by process 27304. > Process 27304 waits for ShareLock on transaction 55576; blocked by > process 27305. > HINT: See server log for query details. > Actually the folowing function is installed on 2 dbs DB1 and DB2. This > function issues an update query on DB3. > When this function is running simultaneously on DB1 and DB2, it produces > a dead lock making one of the functions (in DB1 or DB2) stop with the > above exception: > Is it normal? should'nt postgres be able to handle such situations, for > ex: let one transaction wait untill the other commits or rollback then > continue with the first transaction? > Is there a parameter that should be set in postgresql.conf to allow > handling of concurrent transaction...? > > CREATE OR REPLACE FUNCTION TEST_DB_LINK(VARCHAR) > RETURNS VOID AS' > DECLARE > C INTEGER; > P ALIAS FOR $1; > DUMMY VARCHAR; > BEGIN > C:= 0; > LOOP > EXIT WHEN C > 15; > C:= C+1; > SELECT INTO DUMMY DBLINK_EXEC(''CONNECTION_STRING TO DB3', ''UPDATE > IN_FICHE_PRODUIT SET VALIDE = 1''); > RAISE NOTICE ''%, %'', C,P; > END LOOP; > END;' > LANGUAGE 'plpgsql'; > > Thanks for your time. I think PG is doing what you want.. if you think about it. You start two transactions at the same time. A transaction is defined as "do this set of operations, all of which must succeed or fail atomicly". One transaction cannot update the exact same row as another transaction because that would break the second transactions "must succeed" rule. -Andy