From 230c594950886bf50bf4c69295aa0cb67c16b8a6 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Thu, 15 Apr 2021 20:43:00 +0200 Subject: [PATCH v2] ATTACH PARTITION locking documentation for DEFAULT partitions. --- doc/src/sgml/ddl.sgml | 18 ++++++++++++++++-- doc/src/sgml/ref/alter_table.sgml | 8 ++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 30e4170963..8f0b38847a 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' ); @@ -3947,12 +3950,23 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02 which is otherwise needed to validate the implicit partition constraint. Without the CHECK constraint, the table will be scanned to validate the partition constraint while - holding both an ACCESS EXCLUSIVE lock on that partition - and a SHARE UPDATE EXCLUSIVE lock on the parent table. + holding an ACCESS EXCLUSIVE lock on that partition + and the tables in its downward partition hierarchy (if any), and a + SHARE UPDATE EXCLUSIVE lock on the parent table. It is recommended to drop the now-redundant CHECK 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. If the default partition does + not exclude the to be attached partition constraint, the partition + hierarchy of the default partition will recursively be checked against + the updated partition bounds whilst holding an + ACCESS EXCLUSIVE lock. + + As explained above, it is possible to create indexes on partitioned tables so that they are applied automatically to the entire hierarchy. diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 07e37a6dc8..2801d87827 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -947,8 +947,12 @@ WITH ( MODULUS numeric_literal, REM Attaching a partition acquires a SHARE UPDATE EXCLUSIVE lock on the parent table, - in addition to ACCESS EXCLUSIVE locks on the table - to be attached and on the default partition (if any). + in addition to ACCESS EXCLUSIVE locks on the full + partition hierarchy of the to be attached table and on the default + partition (if any). If the constraints of the default partition do not + already imply the new partition bounds, its descendants will + recursively be locked with an ACCESS EXCLUSIVE lock + and validated against the updated constraints. -- 2.20.1