From 2bf23cd8018c7e2cbff4f00be4aba1e806750998 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Thu, 15 Apr 2021 20:43:00 +0200 Subject: [PATCH v1] ATTACH PARTITION locking documentation for DEFAULT partitions. --- doc/src/sgml/ddl.sgml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 30e4170963..f001f0b8a3 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -3934,6 +3934,9 @@ ALTER TABLE measurement_y2008m02 ADD CONSTRAINT y2008m02 \copy measurement_y2008m02 from 'measurement_y2008m02' -- possibly some other data preparation work +ALTER TABLE measurement_default ADD CONSTRAINT excl_y2008m02 + CHECK ( (logdate >= DATE '2008-02-01' AND logdate < DATE '2008-03-01') IS FALSE ); + ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 FOR VALUES FROM ('2008-02-01') TO ('2008-03-01' ); @@ -3953,6 +3956,21 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 constraint after ATTACH PARTITION is finished. + + Similarly, if you have a default partition on the parent table, it is + recommended to create a CHECK constraint that excludes + the to be attached partition constraint. Here, too, without the + CHECK constraint, this table will be scanned to + validate that the updated default partition constraints while holding + an ACCESS EXCLUSIVE lock on the default partition. + + + + Note that the locks on both the table that is being attached and the + default partition are both recursive to all their child partitions, if + these tables are partitioned tables themselves. + + As explained above, it is possible to create indexes on partitioned tables so that they are applied automatically to the entire hierarchy. -- 2.20.1