Skip to content

Commit 61a9b81

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 8f11115 commit 61a9b81

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

doc/src/sgml/ref/alter_table.sgml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
9999
<para>
100100
<command>ALTER TABLE</command> changes the definition of an existing table.
101101
There are several subforms described below. Note that the lock level required
102-
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is held
103-
unless explicitly noted. When multiple subcommands are listed, the lock
104-
held will be the strictest one required from any subcommand.
102+
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is
103+
acquired unless explicitly noted. When multiple subcommands are given, the
104+
lock acquired will be the strictest one required by any subcommand.
105105

106106
<variablelist>
107107
<varlistentry>
@@ -313,8 +313,8 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
313313
<term><literal>ADD <replaceable class="PARAMETER">table_constraint</replaceable> [ NOT VALID ]</literal></term>
314314
<listitem>
315315
<para>
316-
This form adds a new constraint to a table using the same syntax as
317-
<xref linkend="SQL-CREATETABLE">, plus the option <literal>NOT
316+
This form adds a new constraint to a table using the same constraint
317+
syntax as <xref linkend="sql-createtable">, plus the option <literal>NOT
318318
VALID</literal>, which is currently only allowed for foreign key
319319
and CHECK constraints.
320320
</para>
@@ -335,6 +335,17 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
335335
endterm="sql-altertable-notes-title"> below for more information
336336
about using the <literal>NOT VALID</literal> option.
337337
</para>
338+
339+
<para>
340+
Although most forms of <literal>ADD
341+
<replaceable class="parameter">table_constraint</replaceable></literal>
342+
require an <literal>ACCESS EXCLUSIVE</literal> lock, <literal>ADD
343+
FOREIGN KEY</literal> requires only a <literal>SHARE ROW
344+
EXCLUSIVE</literal> lock. Note that <literal>ADD FOREIGN KEY</literal>
345+
also acquires a <literal>SHARE ROW EXCLUSIVE</literal> lock on the
346+
referenced table, in addition to the lock on the table on which the
347+
constraint is declared.
348+
</para>
338349
</listitem>
339350
</varlistentry>
340351

0 commit comments

Comments
 (0)