Skip to content

Commit a88e588

Browse files
committed
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
1 parent 21b74a1 commit a88e588

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

doc/src/sgml/ref/alter_table.sgml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
141141
<para>
142142
<command>ALTER TABLE</command> changes the definition of an existing table.
143143
There are several subforms described below. Note that the lock level required
144-
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is held
145-
unless explicitly noted. When multiple subcommands are listed, the lock
146-
held will be the strictest one required from any subcommand.
144+
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is
145+
acquired unless explicitly noted. When multiple subcommands are given, the
146+
lock acquired will be the strictest one required by any subcommand.
147147

148148
<variablelist>
149149
<varlistentry>
@@ -364,8 +364,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
364364
<term><literal>ADD <replaceable class="parameter">table_constraint</replaceable> [ NOT VALID ]</literal></term>
365365
<listitem>
366366
<para>
367-
This form adds a new constraint to a table using the same syntax as
368-
<xref linkend="sql-createtable"/>, plus the option <literal>NOT
367+
This form adds a new constraint to a table using the same constraint
368+
syntax as <xref linkend="sql-createtable"/>, plus the option <literal>NOT
369369
VALID</literal>, which is currently only allowed for foreign key
370370
and CHECK constraints.
371371
</para>
@@ -388,9 +388,14 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
388388
</para>
389389

390390
<para>
391-
Addition of a foreign key constraint requires a
392-
<literal>SHARE ROW EXCLUSIVE</literal> lock on the referenced table,
393-
in addition to the lock on the table receiving the constraint.
391+
Although most forms of <literal>ADD
392+
<replaceable class="parameter">table_constraint</replaceable></literal>
393+
require an <literal>ACCESS EXCLUSIVE</literal> lock, <literal>ADD
394+
FOREIGN KEY</literal> requires only a <literal>SHARE ROW
395+
EXCLUSIVE</literal> lock. Note that <literal>ADD FOREIGN KEY</literal>
396+
also acquires a <literal>SHARE ROW EXCLUSIVE</literal> lock on the
397+
referenced table, in addition to the lock on the table on which the
398+
constraint is declared.
394399
</para>
395400

396401
<para>

0 commit comments

Comments
 (0)