aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2021-07-28 15:02:37 +1200
committerDavid Rowley <drowley@postgresql.org>2021-07-28 15:02:37 +1200
commit8709228775b549a2388e6568f463a4115e5a4c10 (patch)
treeedee2df606459fcca26b249862a0eb1805c62046
parent7b7fbe1e8bb4b2a244d1faa618789db411316e55 (diff)
downloadpostgresql-8709228775b549a2388e6568f463a4115e5a4c10.tar.gz
postgresql-8709228775b549a2388e6568f463a4115e5a4c10.zip
Doc: Clarify lock levels taken during ATTACH PARTITION
It wasn't all that clear which lock levels, if any, would be held on the DEFAULT partition during an ATTACH PARTITION operation. Also, clarify which locks will be taken if the DEFAULT partition or the table being attached are themselves partitioned tables. Here I'm only backpatching to v12 as before then we obtained an ACCESS EXCLUSIVE lock on the partitioned table. It seems much less relevant to mention which locks are taken on other tables when the partitioned table itself is locked with an ACCESS EXCLUSIVE lock. Author: Matthias van de Meent, David Rowley Discussion: https://postgr.es/m/CAEze2WiTB6iwrV8W_J=fnrnZ7fowW3qu-8iQ8zCHP3FiQ6+o-A@mail.gmail.com Backpatch-through: 12
-rw-r--r--doc/src/sgml/ddl.sgml28
-rw-r--r--doc/src/sgml/ref/alter_table.sgml13
2 files changed, 36 insertions, 5 deletions
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index 498654876fd..7701d8000f2 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3971,6 +3971,11 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
</para>
<para>
+ The <command>ATTACH PARTITION</command> command requires taking a
+ <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the partitioned table.
+ </para>
+
+ <para>
Before running the <command>ATTACH PARTITION</command> command, it is
recommended to create a <literal>CHECK</literal> constraint on the table to
be attached that matches the expected partition constraint, as
@@ -3978,10 +3983,27 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
which is otherwise needed to validate the implicit
partition constraint. Without the <literal>CHECK</literal> constraint,
the table will be scanned to validate the partition constraint while
- holding both an <literal>ACCESS EXCLUSIVE</literal> lock on that partition
- and a <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the parent table.
+ holding an <literal>ACCESS EXCLUSIVE</literal> lock on that partition.
It is recommended to drop the now-redundant <literal>CHECK</literal>
- constraint after <command>ATTACH PARTITION</command> is finished.
+ constraint after the <command>ATTACH PARTITION</command> is complete. If
+ the table being attached is itself a partitioned table then each of its
+ sub-partitions will be recursively locked and scanned until either a
+ suitable <literal>CHECK</literal> constraint is encountered or the leaf
+ partitions are reached.
+ </para>
+
+ <para>
+ Similarly, if the partitioned table has a <literal>DEFAULT</literal>
+ partition, it is recommended to create a <literal>CHECK</literal>
+ constraint which excludes the to-be-attached partition's constraint. If
+ this is not done then the <literal>DEFAULT</literal> partition will be
+ scanned to verify that it contains no records which should be located in
+ the partition being attached. This operation will be performed whilst
+ holding an <literal>ACCESS EXCLUSIVE</literal> lock on the <literal>
+ DEFAULT</literal> partition. If the <literal>DEFAULT</literal> partition
+ is itself a partitioned table then each of its partitions will be
+ recursively checked in the same way as the table being attached, as
+ mentioned above.
</para>
<para>
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index bf90040aa22..81291577f83 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -976,8 +976,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<para>
Attaching a partition acquires a
<literal>SHARE UPDATE EXCLUSIVE</literal> lock on the parent table,
- in addition to <literal>ACCESS EXCLUSIVE</literal> locks on the table
- to be attached and on the default partition (if any).
+ in addition to the <literal>ACCESS EXCLUSIVE</literal> locks on the table
+ being attached and on the default partition (if any).
+ </para>
+
+ <para>
+ Further locks must also be held on all sub-partitions if the table being
+ attached is itself a partitioned table. Likewise if the default
+ partition is itself a partitioned table. The locking of the
+ sub-partitions can be avoided by adding a <literal>CHECK</literal>
+ constraint as described in
+ <xref linkend="ddl-partitioning-declarative-maintenance"/>.
</para>
</listitem>
</varlistentry>