Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 7F4D681BD2A for ; Tue, 17 Apr 2012 16:37:15 -0300 (ADT) Received: from mx2.d2.com ([66.251.81.121]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SKED1-0006Ta-V3 for pgsql-admin@postgresql.org; Tue, 17 Apr 2012 19:37:14 +0000 Received: from mxb.d2.com ([10.85.4.6]) by mx2.d2.com (8.13.8/8.13.8) with ESMTP id q3HKX6Qg029046 for ; Tue, 17 Apr 2012 13:33:18 -0700 X-ASG-Debug-ID: 1334691391-01d10a6c987c5bf0001-ysJW5H Received: from mail01.d2.com ([172.16.66.171]) by mxb.d2.com with ESMTP id Dp18NdDSVklScxkR for ; Tue, 17 Apr 2012 12:36:31 -0700 (PDT) X-Barracuda-Envelope-From: aalvarez@d2.com Received: from exbew2k3-02.d2.com (exbew2k3-02 [10.78.2.16]) by mail01.d2.com (8.13.8/8.13.8/Debian-3) with ESMTP id q3HJaVd9009730 for ; Tue, 17 Apr 2012 12:36:31 -0700 Received: from [10.126.2.220] ([10.126.2.220] RDNS failed) by exbew2k3-02.d2.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 17 Apr 2012 12:36:30 -0700 Message-ID: <4F8DC63E.7000004@d2.com> Date: Tue, 17 Apr 2012 12:36:30 -0700 From: amador alvarez User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.27) Gecko/20120216 Lightning/1.0b2 Thunderbird/3.1.19 MIME-Version: 1.0 To: 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> X-ASG-Orig-Subj: Re: [ADMIN] Recreate primary key without dropping foreign keys? In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 17 Apr 2012 19:36:30.0857 (UTC) FILETIME=[639CB790:01CD1CD1] X-Barracuda-Connect: UNKNOWN[172.16.66.171] X-Barracuda-Start-Time: 1334691391 X-Barracuda-URL: http://10.85.4.6:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at d2.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.94405 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: NO, score=-2.6 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, RATWARE_GECKO_BUILD autolearn=ham version=3.2.4 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on mx2.d2.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/90 X-Sequence-Number: 39426 Unfortunately I checked out that the deferrable option does not let us drop the PK (postgres8.4) while remaining FK's , I did not try on the constraint as NOT VALID is not supported by postgres8. So unless you have a 9 release or you get a try on a parallel table, you have to follow the manual procedure : Generate new index drop FK's Drop PK Recreate PK swiching to the new index Recreate FK's Can you afford a quick temporary user access to the database? On 04/17/2012 06: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. > > Regards, > Igor Neyman >