Re: declare constraint as valid

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Torsten Förtsch <torsten(dot)foertsch(at)gmx(dot)net>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: declare constraint as valid
Date: 2013-10-12 11:33:24
Message-ID: CAB7nPqQ8SMqPRTzMeBzOpJyFU_1bx0zMYURyswAhcwPpaeQBrw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 10, 2013 at 3:44 AM, Torsten Förtsch
<torsten(dot)foertsch(at)gmx(dot)net> wrote:
> Hi,
>
> assuming a constraint is added to a table as NOT VALID. Now I know it IS
> valid. Can I simply declare it as valid by
>
> update pg_constraint
> set convalidated='t'
> where conrelid=(select c.oid
> from pg_class c
> join pg_namespace n on (n.oid=c.relnamespace)
> where c.relname='tablename'
> and n.nspname='schemaname')
> and conname='constraintname';
>
> instead of
>
> alter table tablename validate constraint ...
>
> Or does the latter have other side effects?
>
> I am asking because I want to avoid the ACCESS EXCLUSIVE lock required
> by the ALTER TABLE. I am sure there are no rows violating the constraint.
You should avoid updating directly the catalogs except if you
absolutely have to. ALTER TABLE does a lot of internal checks and
manipulations of relations when used, so relying on that would be
better IMO. For example in the case of constraint validation there is
processing for inherited relations as far as I recall. Even if you
*know* that the constraint is valid, it is better to play safe
usually. So use the constraint validation when the server is less
busy.

Regards,
--
Michael

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2013-10-12 11:43:01 Re: Need some help on Performance 9.0.4
Previous Message mbetter95 2013-10-12 07:08:34 Re: postgres 9.0.4 configuration and performance issue