Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 32C5881BD27 for ; Tue, 17 Apr 2012 21:03:52 -0300 (ADT) Received: from smtp162.dfw.emailsrvr.com ([67.192.241.162]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SKIND-00078W-6L for pgsql-admin@postgresql.org; Wed, 18 Apr 2012 00:03:51 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp26.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id A6549802A7; Tue, 17 Apr 2012 20:03:38 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp26.relay.dfw1a.emailsrvr.com (Authenticated sender: cernst-AT-zvelo.com) with ESMTPSA id 6EC90800F6; Tue, 17 Apr 2012 20:03:38 -0400 (EDT) Message-ID: <4F8E04D9.6010402@zvelo.com> Date: Tue, 17 Apr 2012 18:03:37 -0600 From: Chris Ernst Organization: Zvelo, Inc. User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120411 Thunderbird/11.0.1 MIME-Version: 1.0 To: Igor Neyman CC: "pgsql-admin@postgresql.org" Subject: Re: Recreate primary key without dropping foreign keys? References: <4F8B6AA1.1040709@zvelo.com> <20120416065717.70a31a6361ac5d7bdad416e8@frank.uvena.de> <4F8BD91C.6070405@zvelo.com> <4F8BDAB2.7010209@frank.uvena.de> <4F8C248E.7070307@zvelo.com> <4F8CC11A.5020003@d2.com> <4F8CDB95.3040407@zvelo.com> In-Reply-To: X-Enigmail-Version: 1.4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201204/91 X-Sequence-Number: 39427 On 04/17/2012 07:43 AM, Igor Neyman wrote: >> -----Original Message----- >> From: Chris Ernst [mailto:cernst@zvelo.com] >> Sent: Monday, April 16, 2012 10:55 PM >> To: pgsql-admin@postgresql.org >> Subject: Re: Recreate primary key without dropping foreign keys? >> >> On 04/16/2012 07:02 PM, amador alvarez wrote: >>> How about deferring the FK's while recreating the PK ? >>> or using a temporary parallel table to be pointed by the other tables >>> (FK) and swap it up on the recreation. >> >> Hmm.. Interesting. But it appears that you have to declare the >> foreign >> key as deferrable at creation. Is there any way to set an existing >> foreign key as deferrable? >> >> - Chris > > May be this (from the docs) would help: > > "ADD table_constraint [ NOT VALID ] > > This form adds a new constraint to a table using the same syntax as CREATE TABLE, plus the option NOT VALID, which is currently only allowed for foreign key constraints. If the constraint is marked NOT VALID, the potentially-lengthy initial check to verify that all rows in the table satisfy the constraint is skipped. The constraint will still be enforced against subsequent inserts or updates (that is, they'll fail unless there is a matching row in the referenced table). But the database will not assume that the constraint holds for all rows in the table, until it is validated by using the VALIDATE CONSTRAINT option." > > Using this option you can drop and recreate corresponding FKs in a very short time, and start using them, while postponing to run "VALIDATE CONSTRAINT" for later. > > It's similar to Oracle's adding FK with "NOCHECK" option, but if IRC there is no need to run "VALIDATE CONSTRAINT" later. Hi Igor, Oooooo... I like the sound of this. I'll give this a shot in the test environment and report back my findings. Thanks a bunch! - Chris