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

Commit f333d35

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 401418c commit f333d35

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
@@ -142,9 +142,9 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
142142
<para>
143143
<command>ALTER TABLE</command> changes the definition of an existing table.
144144
There are several subforms described below. Note that the lock level required
145-
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is held
146-
unless explicitly noted. When multiple subcommands are listed, the lock
147-
held will be the strictest one required from any subcommand.
145+
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is
146+
acquired unless explicitly noted. When multiple subcommands are given, the
147+
lock acquired will be the strictest one required by any subcommand.
148148

149149
<variablelist>
150150
<varlistentry>
@@ -387,8 +387,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
387387
<term><literal>ADD <replaceable class="parameter">table_constraint</replaceable> [ NOT VALID ]</literal></term>
388388
<listitem>
389389
<para>
390-
This form adds a new constraint to a table using the same syntax as
391-
<xref linkend="sql-createtable"/>, plus the option <literal>NOT
390+
This form adds a new constraint to a table using the same constraint
391+
syntax as <xref linkend="sql-createtable"/>, plus the option <literal>NOT
392392
VALID</literal>, which is currently only allowed for foreign key
393393
and CHECK constraints.
394394
</para>
@@ -411,9 +411,14 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
411411
</para>
412412

413413
<para>
414-
Addition of a foreign key constraint requires a
415-
<literal>SHARE ROW EXCLUSIVE</literal> lock on the referenced table,
416-
in addition to the lock on the table receiving the constraint.
414+
Although most forms of <literal>ADD
415+
<replaceable class="parameter">table_constraint</replaceable></literal>
416+
require an <literal>ACCESS EXCLUSIVE</literal> lock, <literal>ADD
417+
FOREIGN KEY</literal> requires only a <literal>SHARE ROW
418+
EXCLUSIVE</literal> lock. Note that <literal>ADD FOREIGN KEY</literal>
419+
also acquires a <literal>SHARE ROW EXCLUSIVE</literal> lock on the
420+
referenced table, in addition to the lock on the table on which the
421+
constraint is declared.
417422
</para>
418423

419424
<para>

0 commit comments

Comments
 (0)