Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f170b57

Browse files
committed
Doc: mention CREATE+ATTACH PARTITION with CREATE TABLE...PARTITION OF.
Clarify that ATTACH/DETACH PARTITION can be used to perform partition maintenance with less locking than straight CREATE TABLE/DROP TABLE. This was already stated in some places, but not emphasized. Back-patch to v14 where DETACH PARTITION CONCURRENTLY was added. (We had lower lock levels for ATTACH PARTITION before that, but this wording wouldn't apply.) Justin Pryzby, reviewed by Robert Treat and Jakub Wartak; a little further wordsmithing by me Discussion: https://postgr.es/m/20220718143304.GC18011@telsasoft.com
1 parent 5b3c595 commit f170b57

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

doc/src/sgml/ddl.sgml

+7-6
Original file line numberDiff line numberDiff line change
@@ -4114,9 +4114,15 @@ CREATE TABLE measurement_y2008m02 PARTITION OF measurement
41144114
</programlisting>
41154115

41164116
As an alternative, it is sometimes more convenient to create the
4117-
new table outside the partition structure, and make it a proper
4117+
new table outside the partition structure, and attach it as a
41184118
partition later. This allows new data to be loaded, checked, and
41194119
transformed prior to it appearing in the partitioned table.
4120+
Moreover, the <literal>ATTACH PARTITION</literal> operation requires
4121+
only <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the
4122+
partitioned table, as opposed to the <literal>ACCESS
4123+
EXCLUSIVE</literal> lock that is required by <command>CREATE TABLE
4124+
... PARTITION OF</command>, so it is more friendly to concurrent
4125+
operations on the partitioned table.
41204126
The <literal>CREATE TABLE ... LIKE</literal> option is helpful
41214127
to avoid tediously repeating the parent table's definition:
41224128

@@ -4136,11 +4142,6 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
41364142
</programlisting>
41374143
</para>
41384144

4139-
<para>
4140-
The <command>ATTACH PARTITION</command> command requires taking a
4141-
<literal>SHARE UPDATE EXCLUSIVE</literal> lock on the partitioned table.
4142-
</para>
4143-
41444145
<para>
41454146
Before running the <command>ATTACH PARTITION</command> command, it is
41464147
recommended to create a <literal>CHECK</literal> constraint on the table to

doc/src/sgml/ref/create_table.sgml

+16-4
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,24 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
615615
</para>
616616

617617
<para>
618-
Operations such as TRUNCATE which normally affect a table and all of its
618+
Operations such as <command>TRUNCATE</command>
619+
which normally affect a table and all of its
619620
inheritance children will cascade to all partitions, but may also be
620-
performed on an individual partition. Note that dropping a partition
621-
with <literal>DROP TABLE</literal> requires taking an <literal>ACCESS
622-
EXCLUSIVE</literal> lock on the parent table.
621+
performed on an individual partition.
623622
</para>
623+
624+
<para>
625+
Note that creating a partition using <literal>PARTITION OF</literal>
626+
requires taking an <literal>ACCESS EXCLUSIVE</literal> lock on the
627+
parent partitioned table. Likewise, dropping a partition
628+
with <command>DROP TABLE</command> requires taking
629+
an <literal>ACCESS EXCLUSIVE</literal> lock on the parent table.
630+
It is possible to use <link linkend="sql-altertable"><command>ALTER
631+
TABLE ATTACH/DETACH PARTITION</command></link> to perform these
632+
operations with a weaker lock, thus reducing interference with
633+
concurrent operations on the partitioned table.
634+
</para>
635+
624636
</listitem>
625637
</varlistentry>
626638

0 commit comments

Comments
 (0)