pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Florian Weimer <fweimer@bfk.de>
Cc: kakarukeys <kakarukeys@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: adding foreign key constraint locks up table
Date: Tue, 28 Dec 2010 10:08:20 -0500
Message-ID: <19238.1293548900@sss.pgh.pa.us> (raw)
In-Reply-To: <82ei926j3p.fsf@mid.bfk.de>
References: <75218696-61be-4730-89f6-dd6058fa9eda@a28g2000prb.googlegroups.com>
	<82ei926j3p.fsf@mid.bfk.de>

Florian Weimer <fweimer@bfk.de> writes:
>> Whenever I try to create a new table "bbb" with foreign key pointing
>> to "aaa". The operation locks, and reading "aaa" is not possible. The
>> query also never seems to finish.

What that sounds like to me is there's some long-running (probably idle)
open transaction that's holding AccessShare lock on aaa.  The ALTER is
blocked waiting for that xact to finish and release its lock.
Everything else queues up behind the ALTER.  A bit of looking in
pg_locks would find the culprit, if this theory is right.

> Do you mean that the ALTER query and subsequent queries are shown as
> "waiting" in pg_stat_activity?  In this case, I'm also wondering why
> this is inecessary.

ALTER ADD FOREIGN KEY must lock both tables to add triggers to them.

			regards, tom lane



view thread (15+ messages)  latest in thread

Message-ID: <19238.1293548900@sss.pgh.pa.us>
Permalink:  ../19238.1293548900@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19238.1293548900@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fweimer@bfk.de, kakarukeys@gmail.com
  Subject: Re: adding foreign key constraint locks up table
  In-Reply-To: <19238.1293548900@sss.pgh.pa.us>

* 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