aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2018-10-25 08:33:17 +0100
committerPeter Eisentraut <peter_e@gmx.net>2018-11-14 17:09:54 +0100
commit1b5d797cd4f7133ff0d18e123fcf41c67a5a7b0b (patch)
tree955a8bd049710d8e3df7c99bfcb49f07b074535c /doc/src
parentb4721f39505b56dd7b556aef5428a0850230ca59 (diff)
downloadpostgresql-1b5d797cd4f7133ff0d18e123fcf41c67a5a7b0b.tar.gz
postgresql-1b5d797cd4f7133ff0d18e123fcf41c67a5a7b0b.zip
Lower lock level for renaming indexes
Change lock level for renaming index (either ALTER INDEX or implicitly via some other commands) from AccessExclusiveLock to ShareUpdateExclusiveLock. One reason we need a strong lock for relation renaming is that the name change causes a rebuild of the relcache entry. Concurrent sessions that have the relation open might not be able to handle the relcache entry changing underneath them. Therefore, we need to lock the relation in a way that no one can have the relation open concurrently. But for indexes, the relcache handles reloads specially in RelationReloadIndexInfo() in a way that keeps changes in the relcache entry to a minimum. As long as no one keeps pointers to rd_amcache and rd_options around across possible relcache flushes, which is the case, this ought to be safe. We also want to use a self-exclusive lock for correctness, so that concurrent DDL doesn't overwrite the rename if they start updating while still seeing the old version. Therefore, we use ShareUpdateExclusiveLock, which is already used by other DDL commands that want to operate in a concurrent manner. The reason this is interesting at all is that renaming an index is a typical part of a concurrent reindexing workflow (CREATE INDEX CONCURRENTLY new + DROP INDEX CONCURRENTLY old + rename back). And indeed a future built-in REINDEX CONCURRENTLY might rely on the ability to do concurrent renames as well. Reviewed-by: Andrey Klychkov <aaklychkov@mail.ru> Reviewed-by: Fabrízio de Royes Mello <fabriziomello@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/1531767486.432607658@f357.i.mail.ru
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/mvcc.sgml12
-rw-r--r--doc/src/sgml/ref/alter_index.sgml9
2 files changed, 14 insertions, 7 deletions
diff --git a/doc/src/sgml/mvcc.sgml b/doc/src/sgml/mvcc.sgml
index 73934e5cf37..bedd9a008d3 100644
--- a/doc/src/sgml/mvcc.sgml
+++ b/doc/src/sgml/mvcc.sgml
@@ -926,10 +926,10 @@ ERROR: could not serialize access due to read/write dependencies among transact
<para>
Acquired by <command>VACUUM</command> (without <option>FULL</option>),
<command>ANALYZE</command>, <command>CREATE INDEX CONCURRENTLY</command>,
- <command>CREATE STATISTICS</command> and
- <command>ALTER TABLE VALIDATE</command> and other
- <command>ALTER TABLE</command> variants (for full details see
- <xref linkend="sql-altertable"/>).
+ <command>CREATE STATISTICS</command>, and certain <command>ALTER
+ INDEX</command> and <command>ALTER TABLE</command> variants (for full
+ details see <xref linkend="sql-alterindex"/> and <xref
+ linkend="sql-altertable"/>).
</para>
</listitem>
</varlistentry>
@@ -970,7 +970,7 @@ ERROR: could not serialize access due to read/write dependencies among transact
</para>
<para>
- Acquired by <command>CREATE TRIGGER</command> and many forms of
+ Acquired by <command>CREATE TRIGGER</command> and some forms of
<command>ALTER TABLE</command> (see <xref linkend="sql-altertable"/>).
</para>
</listitem>
@@ -1020,7 +1020,7 @@ ERROR: could not serialize access due to read/write dependencies among transact
<command>CLUSTER</command>, <command>VACUUM FULL</command>,
and <command>REFRESH MATERIALIZED VIEW</command> (without
<option>CONCURRENTLY</option>)
- commands. Many forms of <command>ALTER TABLE</command> also acquire
+ commands. Many forms of <command>ALTER INDEX</command> and <command>ALTER TABLE</command> also acquire
a lock at this level. This is also the default lock mode for
<command>LOCK TABLE</command> statements that do not specify
a mode explicitly.
diff --git a/doc/src/sgml/ref/alter_index.sgml b/doc/src/sgml/ref/alter_index.sgml
index d0a62123583..6d34dbb74e5 100644
--- a/doc/src/sgml/ref/alter_index.sgml
+++ b/doc/src/sgml/ref/alter_index.sgml
@@ -39,7 +39,10 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
<para>
<command>ALTER INDEX</command> changes the definition of an existing index.
- There are several subforms:
+ 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.
<variablelist>
@@ -53,6 +56,10 @@ ALTER INDEX ALL IN TABLESPACE <replaceable class="parameter">name</replaceable>
or <literal>EXCLUDE</literal>), the constraint is renamed as well.
There is no effect on the stored data.
</para>
+ <para>
+ Renaming an index acquires a <literal>SHARE UPDATE EXCLUSIVE</literal>
+ lock.
+ </para>
</listitem>
</varlistentry>