Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Forcing FK constraint to validated in system catalog

$
0
0

I have a big table (~60gigs, 35mill+ rows) that I need to add a FK to. Adding a FK directly to the table causes a validation which runs for about 30secs that I want avoid as it’s a 30sec access exclusive lock.

I know we have to validate them at some point, but the advantage here is that the new column added will have NULL values for all the existing data as there is no way to compute the relations for the existing data. So, trivially, we can guarantee the referential integrity of this constraint.

Hence, what I want to do is to create the FK constraint as NOT VALID and then force the system catalog (pg_constraint) to read true for the convalidated column.

The 2 questions I have regarding that are:

  1. Is there anything wrong with actually doing this? What are the
    repercussions of forcing this bit if any, what will be affected,
    etc.
  2. What is the point of forcing this? Are these pg_constraint system
    catalog tables, what are they used by? Are they used by the planner
    to make any decisions?

Viewing all articles
Browse latest Browse all 1138

Trending Articles