pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Ernst <cernst@zvelo.com>
To: Igor Neyman <ineyman@perceptron.com>
Cc: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: Recreate primary key without dropping foreign keys?
Date: Tue, 17 Apr 2012 18:03:37 -0600
Message-ID: <4F8E04D9.6010402@zvelo.com> (raw)
In-Reply-To: <A76B25F2823E954C9E45E32FA49D70EC03DACFB6@mail.corp.perceptron.com>
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>
	<A76B25F2823E954C9E45E32FA49D70EC03DACFB6@mail.corp.perceptron.com>

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





view thread (10+ messages)

Message-ID: <4F8E04D9.6010402@zvelo.com>
Permalink:  ../4F8E04D9.6010402@zvelo.com/
Also on:    postgresql.org/message-id/4F8E04D9.6010402@zvelo.com

 · 

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-admin@postgresql.org
  Cc: cernst@zvelo.com, ineyman@perceptron.com
  Subject: Re: Recreate primary key without dropping foreign keys?
  In-Reply-To: <4F8E04D9.6010402@zvelo.com>

* 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