X-Original-To: pgsql-sql@postgresql.org Received: from localhost (unknown [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 7266C92566C for ; Mon, 19 May 2003 20:15:19 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 84179-08 for ; Mon, 19 May 2003 20:15:16 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by developer.postgresql.org (Postfix) with ESMTP id BA0BB925182 for ; Mon, 19 May 2003 18:28:07 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 04E41D621; Mon, 19 May 2003 15:28:06 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id EEB4F5C0B; Mon, 19 May 2003 15:28:06 -0700 (PDT) Date: Mon, 19 May 2003 15:28:06 -0700 (PDT) From: Stephan Szabo To: Matt Mello Cc: Jan Wieck , Tom Lane , Subject: Re: "deadlock detected" / cascading locks In-Reply-To: <3EC944A9.1080404@spaceship.com> Message-ID: <20030519152242.G42425-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/372 X-Sequence-Number: 13537 On Mon, 19 May 2003, Matt Mello wrote: > Jan, can you explain more to a newby like me what you mean by "the > sessions set deferred modes differently?" If a constraint is deferred in one transaction and not in another the order the locks are grabbed could be different. For example you have two constraints A and B, and two transactions T1 and T2. T1 sets constraint A to be deferred, T2 has constraint A being immediate. T1 will get the lock for B first (at end of statement) and then get lock A second (at end of transaction). T2 will get lock A first (at end of statement) and B second (at end of statement). This could cause deadlock if both transactions do something that locks the same rows for A and B and T1 gets the B lock, then T2 gets the A lock, then T2 waits on T1 for the B lock, then T1 waits for T2 on the A lock when it goes to commit. > And, do these locks cascade? If I choose to do an update on table A, > and it has a foreign key to table B, which has a foreign key to table C, > does the update-induced lock on A cause a lock on B /and/ C? Not for checks since those don't change the table in question. It's possible for locks to cascade through referential action effects (although that effect is partially minimized by the bug fix mentioned for update unless the referencing column is itself the one being referenced)