From 722bf7017bbe796decc79c1fde03e7a83dae9ada Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Tue, 8 Feb 2011 12:23:20 +0000 Subject: Extend ALTER TABLE to allow Foreign Keys to be added without initial validation. FK constraints that are marked NOT VALID may later be VALIDATED, which uses an ShareUpdateExclusiveLock on constraint table and RowShareLock on referenced table. Significantly reduces lock strength and duration when adding FKs. New state visible from psql. Simon Riggs, with reviews from Marko Tiikkaja and Robert Haas --- doc/src/sgml/ref/alter_table.sgml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 52f70cea18e..9f02674f44f 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -44,6 +44,8 @@ ALTER TABLE name ALTER [ COLUMN ] column SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } ADD table_constraint ADD table_constraint_using_index + ADD table_constraint [ NOT VALID ] + VALIDATE CONSTRAINT constraint_name DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ] DISABLE TRIGGER [ trigger_name | ALL | USER ] ENABLE TRIGGER [ trigger_name | ALL | USER ] @@ -227,11 +229,27 @@ ALTER TABLE name - ADD table_constraint + ADD table_constraint + [ NOT VALID ] This form adds a new constraint to a table using the same syntax as - . + . Newly added foreign key constraints can + also be defined as NOT VALID to avoid the + potentially lengthy initial check that must otherwise be performed. + Constraint checks are skipped at create table time, so + does not contain this option. + + + + + + VALIDATE CONSTRAINT + + + This form validates a foreign key constraint that was previously created + as NOT VALID. Constraints already marked valid do not + cause an error response. -- cgit v1.2.3