Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 464DE476CA0 for ; Mon, 20 Jan 2003 15:21:59 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id AB116476BD6 for ; Mon, 20 Jan 2003 15:20:16 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h0KKKD5u015370; Mon, 20 Jan 2003 15:20:14 -0500 (EST) To: Ron Mayer Cc: Bhuvan A , pgsql-admin@postgresql.org Subject: Re: deadlock problem in Ad serving.. In-reply-to: References: Comments: In-reply-to Ron Mayer message dated "Mon, 20 Jan 2003 09:58:10 -0800" Date: Mon, 20 Jan 2003 15:20:12 -0500 Message-ID: <15369.1043094012@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/210 X-Sequence-Number: 7052 Ron Mayer writes: > Is it true that the problem happens when updates are done > in a different order by two transactions like this: > trans.1: "update banner_stats set imp=imp+1 where uniqid=4330" > trans.2: "update banner_stats set imp=imp+1 where uniqid=10" > trans.1: "update banner_stats set imp=imp+1 where uniqid=10" > trans.2: "update banner_stats set imp=imp+1 where uniqid=4330" Yeah, I would assume that that's the problem. > If so, then could the problem be avoided if in his application > logic he always did the updates in the same order? ... I.e. Make > sure the each transaction does the updates in the same order by > sorting his updates based on uniqid in the client? If I understood correctly, he's tracking webpage hits; so the updates are going to correspond to the sequence in which visitors move to different webpages. I don't think he can force a particular order (and if he could, there'd be little need for the per-page counts anyway). I suppose he could hold all the updates in a temp table and apply them in a sorted order at end of transaction, but that seems like a pain. I would suggest using a separate transaction for each webpage visited. Holding a transaction open across multiple page traversals is widely considered bad news for a number of reasons, not only this one. regards, tom lane