X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F394952833 for ; Sun, 19 Jun 2005 12:58:22 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67526-02 for ; Sun, 19 Jun 2005 15:58:17 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id DED875281E for ; Sun, 19 Jun 2005 12:58:16 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j5JFwCkk072854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 19 Jun 2005 09:58:14 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j5JFwCL9019298; Sun, 19 Jun 2005 09:58:12 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j5JFwBpr019297; Sun, 19 Jun 2005 09:58:11 -0600 (MDT) (envelope-from mfuhr) Date: Sun, 19 Jun 2005 09:58:11 -0600 From: Michael Fuhr To: Vilinski Vladimir Cc: pgsql-sql@postgresql.org Subject: Re: WHY transaction waits for another transaction? Message-ID: <20050619155811.GA18897@winnie.fuhr.org> References: <141218891@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <141218891@web.de> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/239 X-Sequence-Number: 21840 On Tue, Jun 14, 2005 at 01:12:13PM +0200, Vilinski Vladimir wrote: > > During the execution of transaction Nr:10295 (PID:18430) one new transaction with > Nr:10339 (PID:18431) starts, that writes one record into the table. But this new > transaction never stops, because it tries to set one ShareLock to its > parrent transaction Nr:10295. > > My problem is, how can i found out - WHY the second transaction waits > for end of first transaction? > Is there a tool for analyzing such deadlocks? A note on terminology: what you describe doesn't sound like deadlock, it sounds like blocking. Deadlock occurs, for example, when two transactions each hold a lock that the other is waiting for; PostgreSQL should detect this situation and raise an error in one of the transactions. What you describe sounds more like one transaction blocking because of a lock held by another transaction. You say that process 18431 "writes one record into the table," so I assume it's doing an INSERT. That should acquire a RowExclusiveLock on the table being inserted into; based on your pg_locks output that would be either relation 251472 or 251487. Does that table have foreign key references to other tables? I see several instances of RowShareLock, which is acquired by SELECT FOR UPDATE, which is done by foreign key constraint checks (although that's not the only possibility -- you might have executed SELECT FOR UPDATE yourself). In released versions of PostgreSQL, if two transactions insert or update records that refer to the same foreign key, then one transaction will block until the other completes, due to that SELECT FOR UPDATE (which prevents the foreign key from changing before the referring transaction completes; this blocking situation will be fixed in the next release). I'm guessing that foreign key references are causing the blocking. If possible, it would be best to commit transactions that insert or update foreign keys as soon as possible. -- Michael Fuhr http://www.fuhr.org/~mfuhr/