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 2B6165281F for ; Sun, 19 Jun 2005 12:05:32 -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 53819-07 for ; Sun, 19 Jun 2005 15:05:26 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9631F5280B for ; Sun, 19 Jun 2005 12:05:23 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j5JF5M2Y017563; Sun, 19 Jun 2005 11:05:22 -0400 (EDT) To: Vilinski Vladimir Cc: pgsql-sql@postgresql.org Subject: Re: WHY transaction waits for another transaction? In-reply-to: <141218891@web.de> References: <141218891@web.de> Comments: In-reply-to Vilinski Vladimir message dated "Tue, 14 Jun 2005 13:12:13 +0200" Date: Sun, 19 Jun 2005 11:05:22 -0400 Message-ID: <17562.1119193522@sss.pgh.pa.us> From: Tom Lane 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/238 X-Sequence-Number: 21839 Vilinski Vladimir writes: > 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? Presumably it is blocked on a row lock that the first transaction holds. There isn't any really good way to find out exactly which row is involved in existing releases (8.1 will be better). If you're desperate you could go in with a debugger, but it's probably easier to reason it out, because there are not that many possibilities. One way to get this would be if the two transactions tried to update the same rows in different orders. But I think that would be a deadlock condition in Oracle too, so if your code worked on Oracle that's probably not it. The more likely suspect is a foreign key conflict. Are both transactions inserting/updating rows that could reference the same row(s) in a master table? PG takes a row lock on the referenced row (to make sure it won't disappear before commit) and so you can get deadlocks in the master table. PG 8.1 will have sharable row locks and use those for foreign key interlocks, so this problem should essentially disappear in 8.1. At the moment, the best workaround I know of is to make the foreign key checks all deferred, so that they're not checked until the transaction is about to commit. This is not bulletproof, but because it considerably reduces the time window for a conflict, it may do as a workaround until 8.1 is ready. regards, tom lane