ALTER TABLE VALIDATE CONSTRAINT w/o lock

From: Torsten Förtsch <torsten(dot)foertsch(at)gmx(dot)net>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: ALTER TABLE VALIDATE CONSTRAINT w/o lock
Date: 2013-10-08 14:35:58
Message-ID: 5254184E.3040408@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I want to add a new column named sell_time to a table which already has
a boolean field named is_sold. Then I want to create a new check constraint:

ALTER TABLE ...
CHECK(is_sold AND sell_time IS NOT NULL OR
NOT is_sold AND sell_time IS NULL)
NOT VALID;

The constraint is added as NOT VALID for 2 reasons. 1) it is not valid
at that point and 2) I cannot afford the lock required to validate the it.

According to the docs subsequent operations on the table must pass the
constraint.

Now I can slowly populate the new column. After a while I'll reach a
point where the constraint is valid for all rows.

How can I tell that the database without the re-validation?

Alternatively, is there a way to make the constraint validation really
fast (a few seconds at most for 50.000.000 rows)? (this is 9.3)

Thanks,
Torsten

Browse pgsql-general by date

  From Date Subject
Next Message shailesh singh 2013-10-08 15:03:26 Re: [GENERAL] Urgent Help Required
Previous Message David Johnston 2013-10-08 13:27:51 Re: Urgent Help Required