aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-04-10 13:12:58 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-04-10 13:12:58 -0400
commitf333d35428c1cba8d35065b6dbb2dd46e18bd929 (patch)
treeae2d1bb07c1a9637e800e78551df43c65debdb0a /doc/src
parent401418ca6a689f772cbfa1aedc7485cbbcde7a94 (diff)
downloadpostgresql-f333d35428c1cba8d35065b6dbb2dd46e18bd929.tar.gz
postgresql-f333d35428c1cba8d35065b6dbb2dd46e18bd929.zip
Doc: clarify locking requirements for ALTER TABLE ADD FOREIGN KEY.
The docs explained that a SHARE ROW EXCLUSIVE lock is needed on the referenced table, but failed to say the same about the table being altered. Since the page says that ACCESS EXCLUSIVE lock is taken unless otherwise stated, this left readers with the wrong conclusion. Discussion: https://postgr.es/m/834603375.3470346.1586482852542@mail.yahoo.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/alter_table.sgml21
1 files changed, 13 insertions, 8 deletions
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml
index e4861964774..7595e609b5b 100644
--- a/doc/src/sgml/ref/alter_table.sgml
+++ b/doc/src/sgml/ref/alter_table.sgml
@@ -142,9 +142,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<para>
<command>ALTER TABLE</command> changes the definition of an existing table.
There are several subforms described below. Note that the lock level required
- may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is held
- unless explicitly noted. When multiple subcommands are listed, the lock
- held will be the strictest one required from any subcommand.
+ may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is
+ acquired unless explicitly noted. When multiple subcommands are given, the
+ lock acquired will be the strictest one required by any subcommand.
<variablelist>
<varlistentry>
@@ -387,8 +387,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
<term><literal>ADD <replaceable class="parameter">table_constraint</replaceable> [ NOT VALID ]</literal></term>
<listitem>
<para>
- This form adds a new constraint to a table using the same syntax as
- <xref linkend="sql-createtable"/>, plus the option <literal>NOT
+ This form adds a new constraint to a table using the same constraint
+ syntax as <xref linkend="sql-createtable"/>, plus the option <literal>NOT
VALID</literal>, which is currently only allowed for foreign key
and CHECK constraints.
</para>
@@ -411,9 +411,14 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
</para>
<para>
- Addition of a foreign key constraint requires a
- <literal>SHARE ROW EXCLUSIVE</literal> lock on the referenced table,
- in addition to the lock on the table receiving the constraint.
+ Although most forms of <literal>ADD
+ <replaceable class="parameter">table_constraint</replaceable></literal>
+ require an <literal>ACCESS EXCLUSIVE</literal> lock, <literal>ADD
+ FOREIGN KEY</literal> requires only a <literal>SHARE ROW
+ EXCLUSIVE</literal> lock. Note that <literal>ADD FOREIGN KEY</literal>
+ also acquires a <literal>SHARE ROW EXCLUSIVE</literal> lock on the
+ referenced table, in addition to the lock on the table on which the
+ constraint is declared.
</para>
<para>