pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lew <noone@lewscanon.com>
To: pgsql-performance@postgresql.org
Subject: Re: adding foreign key constraint locks up table
Date: Tue, 28 Dec 2010 08:34:30 -0500
Message-ID: <ifcp05$odt$1@news.albasani.net> (raw)
In-Reply-To: <75218696-61be-4730-89f6-dd6058fa9eda@a28g2000prb.googlegroups.com>
References: <75218696-61be-4730-89f6-dd6058fa9eda@a28g2000prb.googlegroups.com>

On 12/28/2010 02:08 AM, kakarukeys wrote:
> I have a table "aaa" which is not very big. It has less than 10'000
> rows. However read operations on this table is very frequent.
>
> 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.

How long did you wait?

> ALTER TABLE "bbb" ADD CONSTRAINT "topic_id_refs_id_3942a46c6ab2c0b4"
> FOREIGN KEY ("topic_id") REFERENCES "aaa" ("id") DEFERRABLE INITIALLY
> DEFERRED;
>
> The current workaround is to create any new table at off-peak hours,
> e.g. [sic] midnight after restarting the db.
>
> I would like to know if there's any proper solution of this. Is this
> an issue affecting all relational databases? My db is PostgreSQL 8.3.

Naturally the system has to lock the table to alter it.  It also has to check 
that all records already in "bbb" satisfy the new constraint.

What's the longest you've waited for ALTER TABLE to release its lock?

-- 
Lew
Ceci n'est pas une pipe.



view thread (15+ messages)  latest in thread

Message-ID: <ifcp05$odt$1@news.albasani.net>
Permalink:  ../ifcp05$odt$1@news.albasani.net/
Also on:    postgresql.org/message-id/ifcp05$odt$1@news.albasani.net

 · 

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: noone@lewscanon.com
  Subject: Re: adding foreign key constraint locks up table
  In-Reply-To: <ifcp05$odt$1@news.albasani.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