0

We have a partitioned table from which we attach and detach partitions for archiving purposes. When attempting to add a foreign key on the partitioned table, the process is taking a long time (up to 20 minutes) which is causing many problems.

We have discussed using a NOT VALID option, but unfortunately this is not an option for partition tables, so just wanted to see if there were any options to add a foreign key to a partition

2
  • I have no problems defining a NOT VALID foreign key on a partition. Or are you talking about a foreign key defined on the partitioned table? Commented Jul 16 at 13:03
  • Apologies on the partitioned table
    – Krishnp92
    Commented Jul 16 at 13:10

1 Answer 1

0

I recommend that you do not create a foreign key constraint on the partitioned table. If you do that, attaching partitions will always be slow, because the constraint has to be validated for all rows in the new partition.

My recommendation is to create the foreign key constraint on the individual partitions. You don't lose anything that way, and your problem vanishes, because you can create NOT VALID foreign key constraints on the partitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.