Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 650BB475DDA; Tue, 31 Dec 2002 22:38:06 -0500 (EST) Received: from kaukau.mcs.vuw.ac.nz (kaukau.mcs.vuw.ac.nz [130.195.5.20]) by postgresql.org (Postfix) with ESMTP id 6696D475B47; Tue, 31 Dec 2002 22:38:05 -0500 (EST) Received: from devon.mcs.vuw.ac.nz (devon.mcs.vuw.ac.nz [130.195.5.109]) by kaukau.mcs.vuw.ac.nz (8.12.6/8.12.6) with ESMTP id h013c8C6008672 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT); Wed, 1 Jan 2003 16:38:09 +1300 (NZDT) Received: from localhost (localhost [[UNIX: localhost]]) by devon.mcs.vuw.ac.nz (8.11.6/8.11.1) id h013c6R05361; Wed, 1 Jan 2003 16:38:06 +1300 (NZDT) Content-Type: text/plain; charset="us-ascii" From: Minghann Ho To: pgsql-performance@postgresql.org, pgsql-performance-owner@postgresql.org, pgsql-admin@postgresql.org Subject: alter table TBL add constraint TBL_FK foreign key ... very slow Date: Wed, 1 Jan 2003 16:38:06 +1300 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200301011638.06045.mho@mcs.vuw.ac.nz> X-Scanned-By: MIMEDefang 2.24 (www . roaringpenguin . com / mimedefang) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/230 X-Sequence-Number: 646 Hi all, I've experienced very slow performance to add foreign key constraints using ALTER TABLE ADD CONSTRAINT FOREIGN KEY ... After using COPY ... FROM to load the base tables, I started to build the referential integrity between tables. I have 3 tables: T1 (6 million records), T2 (1.5 million records) and T3 (0.8 million records). One of the RI - foreign key (T1 -> T2) constraint took about 70 hrs to build. The other RI - foreign key (T1 -> T3) constraint took about 200 hrs and yet completed!! (compound foreign key) I tried to use small subset of the tables of T2 and T3 to do the testing. An estimation show that it need about 960 hrs to build the RI - foreign key constraints on table T1 -> T3 !!! I've read in the archives that some people suffered slow performance of this problem in Aug 2000, but there was no further information about the solution. Please anyone who has experience in this issues can give me some hint. Thanks Hans