From: Andrew - Supernews <andrew+nonews@supernews.com>
To: pgsql-sql@postgresql.org
Subject: Re: AutoCommit and DDL
Date: Tue, 01 Mar 2005 01:09:18 -0000
Message-ID: <slrnd27g5u.2shl.andrew+nonews@trinity.supernews.net> (raw)
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>
On 2005-03-01, Don Drake <dondrake@gmail.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: andrew+nonews@supernews.com
Subject: Re: AutoCommit and DDL
In-Reply-To: <slrnd27g5u.2shl.andrew+nonews@trinity.supernews.net>
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> <slrnd27g5u.2shl.andrew+nonews@trinity.supernews.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox