X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7BB2A4769B2 for ; Thu, 15 May 2003 14:13:35 -0400 (EDT) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with ESMTP id 64463-01 for ; Thu, 15 May 2003 14:13:03 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id C4BE64769DC for ; Thu, 15 May 2003 12:49:38 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h4FGnhU6010097; Thu, 15 May 2003 12:49:44 -0400 (EDT) To: Matt Mello Cc: pgsql-sql@postgresql.org Subject: Re: "deadlock detected" documentation In-reply-to: <3EC3C239.7070708@spaceship.com> References: <3EB82DA1.7020809@spaceship.com> <24809.1052282819@sss.pgh.pa.us> <3EC32935.5040005@spaceship.com> <7737.1053003625@sss.pgh.pa.us> <3EC3C239.7070708@spaceship.com> Comments: In-reply-to Matt Mello message dated "Thu, 15 May 2003 11:37:13 -0500" Date: Thu, 15 May 2003 12:49:43 -0400 Message-ID: <10096.1053017383@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/329 X-Sequence-Number: 13494 Matt Mello writes: > There are no triggers or rules except for the foreign keys. > The txn table has several foreign keys. You are probably getting deadlocks on the rows referenced by the foreign keys, then. As of the current release, each UPDATEd row will cause the foreign-key triggers to grab a row lock (SELECT FOR UPDATE lock) on the referenced row in the other table. If you have concurrent updates touching rows that reference the same other-table rows, it's possible to get a deadlock depending on the order in which the updates happen to occur. There is no particularly good SQL-level workaround for this; the only one I can think of is to do the updates one row at a time (or at least one foreign-key value at a time), which sucks. There is a patch in CVS tip that alleviates the problem substantially by not taking a foreign-table lock when the foreign key value isn't being changed by the UPDATE, which is commonly the case (although I'm not entirely sure that it will help you, since you do seem to be updating the referencing column). If you want to try it, I believe Jan Wieck posted a 7.3 version of the patch a month or so ago. regards, tom lane