update ALTER TABLE with ATTACH PARTITION lock mode
commit #898e5e32 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock)
updates ddl.sgml but not alter_table.sgml, which only says:
https://www.postgresql.org/docs/12/release-12.html
|An ACCESS EXCLUSIVE lock is held unless explicitly noted.
Find attached patch, which also improve language in several related places.
"Without such a constraint": SUCH could refer to either of the constraints..
"because it is no longer necessary.": In our use case, we prefer to keep the
redundant constraint, to avoid having to add it back if we detach/reattach
again in the future..
Attachments:
v1-0001-Mention-reduced-locking-strength-of-ATTACH-PARTIT.patchtext/x-diff; charset=us-asciiDownload
From c820a81fba0a6c2388ec58fc0204ca833523e81e Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sun, 27 Oct 2019 18:54:24 -0500
Subject: [PATCH v1 1/2] Mention reduced locking strength of ATTACH PARTITION..
See commit 898e5e32
---
doc/src/sgml/ref/alter_table.sgml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index c8dfa19..a184bed 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -900,6 +900,13 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
the scan of the new partition, it is always skipped when the default
partition is a foreign table.
</para>
+
+ <para>
+ Attaching a partition acquires a <literal>SHARE UPDATE EXCLUSIVE</literal>
+ lock on the partitioned table, in addition to an
+ <literal>ACCESS EXCLUSIVE</literal> lock on the partition.
+ </para>
+
</listitem>
</varlistentry>
--
2.7.4
v1-0002-Tweak-language-for-ATTACH-PARTITION-docs.patchtext/x-diff; charset=us-asciiDownload
From b1c9c50228ebd3d2d511382ebd6cbae08788e376 Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sun, 27 Oct 2019 18:38:23 -0500
Subject: [PATCH v1 2/2] Tweak language for ATTACH PARTITION docs
---
doc/src/sgml/ddl.sgml | 8 ++++----
doc/src/sgml/ref/alter_table.sgml | 12 ++++++------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index b097b80..8b60d8b 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3972,14 +3972,14 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
<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 describing the desired partition constraint. That way,
+ be attached matching the desired partition constraint. That way,
the system will be able to skip the scan which is otherwise needed to validate the implicit
- partition constraint. Without such a constraint, the table will be
+ partition constraint. Without the <literal>CHECK</literal> constraint, the table will be
scanned to validate the partition constraint while holding an
<literal>ACCESS EXCLUSIVE</literal> lock on that partition
and a <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the parent table.
- One may then drop the constraint after <command>ATTACH PARTITION</command>
- is finished, because it is no longer necessary.
+ It may be desired to drop the redundant <literal>CHECK</literal> constraint
+ after <command>ATTACH PARTITION</command> is finished.
</para>
<para>
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index a184bed..91ec626 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -841,7 +841,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
or as a default partition by using <literal>DEFAULT</literal>.
For each index in the target table, a corresponding
one will be created in the attached table; or, if an equivalent
- index already exists, will be attached to the target table's index,
+ index already exists, it will be attached to the target table's index,
as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
Note that if the existing table is a foreign table, it is currently not
allowed to attach the table as a partition of the target table if there
@@ -864,17 +864,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
already exist.
If any of the <literal>CHECK</literal> constraints of the table being
attached are marked <literal>NO INHERIT</literal>, the command will fail;
- such a constraint must be recreated without the <literal>NO INHERIT</literal>
+ such constraints must be recreated without the <literal>NO INHERIT</literal>
clause.
</para>
<para>
If the new partition is a regular table, a full table scan is performed
- to check that no existing row in the table violates the partition
+ to check that existing rows in the table do not violate the partition
constraint. It is possible to avoid this scan by adding a valid
- <literal>CHECK</literal> constraint to the table that would allow only
- the rows satisfying the desired partition constraint before running this
- command. It will be determined using such a constraint that the table
+ <literal>CHECK</literal> constraint to the table that allows only
+ rows satisfying the desired partition constraint before running this
+ command. The <literal>CHECK</literal> constraint will be used to determine that the table
need not be scanned to validate the partition constraint. This does not
work, however, if any of the partition keys is an expression and the
partition does not accept <literal>NULL</literal> values. If attaching
--
2.7.4
On Sun, Oct 27, 2019 at 07:12:07PM -0500, Justin Pryzby wrote:
commit #898e5e32 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock)
updates ddl.sgml but not alter_table.sgml, which only says:https://www.postgresql.org/docs/12/release-12.html
|An ACCESS EXCLUSIVE lock is held unless explicitly noted.
+ <para>
+ Attaching a partition acquires a <literal>SHARE UPDATE EXCLUSIVE</literal>
+ lock on the partitioned table, in addition to an
+ <literal>ACCESS EXCLUSIVE</literal> lock on the partition.
+ </para>
Updating the docs of ALTER TABLE sounds like a good idea. This
sentence looks fine to me. Perhaps others have suggestions?
Find attached patch, which also improve language in several related places.
Not sure that these are actually improvements.
--
Michael
On 2019-Oct-28, Michael Paquier wrote:
On Sun, Oct 27, 2019 at 07:12:07PM -0500, Justin Pryzby wrote:
commit #898e5e32 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock)
updates ddl.sgml but not alter_table.sgml, which only says:https://www.postgresql.org/docs/12/release-12.html
|An ACCESS EXCLUSIVE lock is held unless explicitly noted.+ <para> + Attaching a partition acquires a <literal>SHARE UPDATE EXCLUSIVE</literal> + lock on the partitioned table, in addition to an + <literal>ACCESS EXCLUSIVE</literal> lock on the partition. + </para> Updating the docs of ALTER TABLE sounds like a good idea. This sentence looks fine to me. Perhaps others have suggestions?
Doesn't the command also acquire a lock on the default partition if
there is one? It sounds worth noting.
Find attached patch, which also improve language in several related places.
Not sure that these are actually improvements.
I think some of them (most?) are clear improvements.
--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On Mon, Oct 28, 2019 at 12:06:44PM -0300, Alvaro Herrera wrote:
On 2019-Oct-28, Michael Paquier wrote:
On Sun, Oct 27, 2019 at 07:12:07PM -0500, Justin Pryzby wrote:
commit #898e5e32 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock)
updates ddl.sgml but not alter_table.sgml, which only says:https://www.postgresql.org/docs/12/release-12.html
|An ACCESS EXCLUSIVE lock is held unless explicitly noted.+ <para> + Attaching a partition acquires a <literal>SHARE UPDATE EXCLUSIVE</literal> + lock on the partitioned table, in addition to an + <literal>ACCESS EXCLUSIVE</literal> lock on the partition. + </para> Updating the docs of ALTER TABLE sounds like a good idea. This sentence looks fine to me. Perhaps others have suggestions?Doesn't the command also acquire a lock on the default partition if
there is one? It sounds worth noting.
I suppose it should something other than partition(ed), since partitions can be
partitioned, too...
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 child table and the
<literal>DEFAULT</literal> partition (if any).
Thanks,
Justin
Hello,
On Tue, Oct 29, 2019 at 12:13 AM Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
On 2019-Oct-28, Michael Paquier wrote:
On Sun, Oct 27, 2019 at 07:12:07PM -0500, Justin Pryzby wrote:
commit #898e5e32 (Allow ATTACH PARTITION with only ShareUpdateExclusiveLock)
updates ddl.sgml but not alter_table.sgml, which only says:https://www.postgresql.org/docs/12/release-12.html
|An ACCESS EXCLUSIVE lock is held unless explicitly noted.+ <para> + Attaching a partition acquires a <literal>SHARE UPDATE EXCLUSIVE</literal> + lock on the partitioned table, in addition to an + <literal>ACCESS EXCLUSIVE</literal> lock on the partition. + </para> Updating the docs of ALTER TABLE sounds like a good idea. This sentence looks fine to me. Perhaps others have suggestions?Doesn't the command also acquire a lock on the default partition if
there is one? It sounds worth noting.Find attached patch, which also improve language in several related places.
Not sure that these are actually improvements.
I think some of them (most?) are clear improvements.
As someone who has written some of those lines, I agree that Justin's
tweaks make them more readable, so +1 to apply 0002 patch too.
Thanks,
Amit
On Mon, Oct 28, 2019 at 10:56:33PM -0500, Justin Pryzby wrote:
I suppose it should something other than partition(ed), since partitions can be
partitioned, too...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 child table and the
<literal>DEFAULT</literal> partition (if any).
In this context, "on the child table" sounds a bit confusing? Would
it make more sense to say the "on the table to be attached" instead?
--
Michael
On Thu, Oct 31, 2019 at 06:07:34PM +0900, Michael Paquier wrote:
On Mon, Oct 28, 2019 at 10:56:33PM -0500, Justin Pryzby wrote:
I suppose it should something other than partition(ed), since partitions can be
partitioned, too...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 child table and the
<literal>DEFAULT</literal> partition (if any).In this context, "on the child table" sounds a bit confusing? Would
it make more sense to say the "on the table to be attached" instead?
I guess you mean because it's not a child until after the ALTER. Yes, that
makes sense.
Thanks,
Justin
On Fri, Nov 01, 2019 at 08:59:48AM -0500, Justin Pryzby wrote:
I guess you mean because it's not a child until after the ALTER. Yes, that
makes sense.
Yes, perhaps you have another idea than mine on how to shape this
sentence?
--
Michael
On Fri, Nov 01, 2019 at 11:01:22PM +0900, Michael Paquier wrote:
On Fri, Nov 01, 2019 at 08:59:48AM -0500, Justin Pryzby wrote:
I guess you mean because it's not a child until after the ALTER. Yes, that
makes sense.Yes, perhaps you have another idea than mine on how to shape this
sentence?
I can't think of anything better.
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 the <literal>DEFAULT</literal> partition (if
any).
Justin
On Fri, Nov 01, 2019 at 11:58:43AM -0500, Justin Pryzby wrote:
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 the <literal>DEFAULT</literal> partition (if
any).
Sounds fine. So gathering everything I get the attached. Any
thoughts from others?
--
Michael
Attachments:
partition-docs-v3.patchtext/x-diff; charset=us-asciiDownload
diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml
index d7158c1b03..8e5592c106 100644
--- a/doc/src/sgml/ddl.sgml
+++ b/doc/src/sgml/ddl.sgml
@@ -3952,14 +3952,14 @@ ALTER TABLE measurement ATTACH PARTITION measurement_y2008m02
<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 describing the desired partition constraint. That way,
+ be attached matching the desired partition constraint. That way,
the system will be able to skip the scan to validate the implicit
- partition constraint. Without such a constraint, the table will be
+ partition constraint. Without the <literal>CHECK</literal> constraint, the table will be
scanned to validate the partition constraint while holding an
<literal>ACCESS EXCLUSIVE</literal> lock on that partition
and a <literal>SHARE UPDATE EXCLUSIVE</literal> lock on the parent table.
- One may then drop the constraint after <command>ATTACH PARTITION</command>
- is finished, because it is no longer necessary.
+ It may be desired to drop the redundant <literal>CHECK</literal> constraint
+ after <command>ATTACH PARTITION</command> is finished.
</para>
<para>
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index 62542cd8a1..d3a37b4a6a 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -841,7 +841,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
or as a default partition by using <literal>DEFAULT</literal>.
For each index in the target table, a corresponding
one will be created in the attached table; or, if an equivalent
- index already exists, will be attached to the target table's index,
+ index already exists, it will be attached to the target table's index,
as if <command>ALTER INDEX ATTACH PARTITION</command> had been executed.
Note that if the existing table is a foreign table, it is currently not
allowed to attach the table as a partition of the target table if there
@@ -864,17 +864,17 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
already exist.
If any of the <literal>CHECK</literal> constraints of the table being
attached is marked <literal>NO INHERIT</literal>, the command will fail;
- such a constraint must be recreated without the <literal>NO INHERIT</literal>
+ such constraints must be recreated without the <literal>NO INHERIT</literal>
clause.
</para>
<para>
If the new partition is a regular table, a full table scan is performed
- to check that no existing row in the table violates the partition
+ to check that existing rows in the table do not violate the partition
constraint. It is possible to avoid this scan by adding a valid
- <literal>CHECK</literal> constraint to the table that would allow only
- the rows satisfying the desired partition constraint before running this
- command. It will be determined using such a constraint that the table
+ <literal>CHECK</literal> constraint to the table that allows only
+ rows satisfying the desired partition constraint before running this
+ command. The <literal>CHECK</literal> constraint will be used to determine that the table
need not be scanned to validate the partition constraint. This does not
work, however, if any of the partition keys is an expression and the
partition does not accept <literal>NULL</literal> values. If attaching
@@ -900,6 +900,14 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
the scan of the new partition, it is always skipped when the default
partition is a foreign table.
</para>
+
+ <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 the default partition (if any).
+ </para>
+
</listitem>
</varlistentry>