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 76CFF56616 for ; Tue, 1 Mar 2005 01:09:21 +0000 (GMT) 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 17560-05 for ; Tue, 1 Mar 2005 01:09:18 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.250.190.2]) by svr1.postgresql.org (Postfix) with ESMTP id B545D56526 for ; Tue, 1 Mar 2005 01:09:17 +0000 (GMT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 0612F31908; Tue, 1 Mar 2005 02:09:21 +0100 (MET) From: Andrew - Supernews X-Newsgroups: pgsql.sql Subject: Re: AutoCommit and DDL Date: Tue, 01 Mar 2005 01:09:18 -0000 Organization: http://www.supernews.com - all your nntp are belong to us Message-ID: References: <6c21003b050226125634e9964@mail.gmail.com> <20050227042043.GB77382@winnie.fuhr.org> <6c21003b0502270955673432e7@mail.gmail.com> <20050227195434.GA21745@winnie.fuhr.org> <6c21003b0502271755fb9b917@mail.gmail.com> <20050228033355.GA1296@winnie.fuhr.org> <6c21003b050228164078bb435a@mail.gmail.com> Reply-To: andrew@supernews.com User-Agent: slrn/0.9.8.0 (FreeBSD) X-Complaints-To: abuse@supernews.com Lines: 41 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/3 X-Sequence-Number: 20482 On 2005-03-01, Don Drake wrote: > I don't think it would be easy to duplicate since our code base is > quite extensive. > > Basically, what was happening was a script would first open a database > connection (AutoCommit turned off by default), create a few objects > (that also opened independent db connections), the objects would run > queries so they have data populated, an insert is done and committed, > then we call a generic function that will create a new table (using > inherits, part of our partitioning) as well as adding indexes and > constraints to this new table. It would get to a point in the > function where it was adding a FK constraint and every query against > the table would "hang" which appeared to be some exclusive lock not > being released. Activity on the DB would be 100% idle during this > period, the alter table never came back so we killed it each time. I > commented out the code doing the FK constraint add and everything > worked just fine. This sounds as though your application deadlocked against itself - by using multiple connections without autocommit, you can easily get into situations where you are waiting for completion on one connection, which is blocked waiting for a lock held by another connection - the lock remains until the second connection commits, which never happens since the app is waiting on the first. The DB can't detect this as a deadlock because it does not know that one session is waiting on another on the client side; deadlock detection considers only sessions waiting _inside the server_. This situation isn't specific to DDL, but is easier to produce that way since most DDL operations acquire very high level locks (often AccessExclusive, which blocks queries). > As a test I moved the partition function call to the beginning of the > script (before the objects were created) and it worked just fine. I > then changed the object declarations passing in the single DB handle, > and every now works just fine. This is consistent with it being a client-side deadlock. -- Andrew, Supernews http://www.supernews.com - individual and corporate NNTP services