mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Add TABLESPACE option to REINDEX
This patch adds the possibility to move indexes to a new tablespace while rebuilding them. Both the concurrent and the non-concurrent cases are supported, and the following set of restrictions apply: - When using TABLESPACE with a REINDEX command that targets a partitioned table or index, all the indexes of the leaf partitions are moved to the new tablespace. The tablespace references of the non-leaf, partitioned tables in pg_class.reltablespace are not changed. This requires an extra ALTER TABLE SET TABLESPACE. - Any index on a toast table rebuilt as part of a parent table is kept in its original tablespace. - The operation is forbidden on system catalogs, including trying to directly move a toast relation with REINDEX. This results in an error if doing REINDEX on a single object. REINDEX SCHEMA, DATABASE and SYSTEM skip system relations when TABLESPACE is used. Author: Alexey Kondratov, Michael Paquier, Justin Pryzby Reviewed-by: Álvaro Herrera, Michael Paquier Discussion: https://postgr.es/m/8a8f5f73-00d3-55f8-7583-1375ca8f6a91@postgrespro.ru
This commit is contained in:
@ -26,6 +26,7 @@ REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { IN
|
||||
<phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase>
|
||||
|
||||
CONCURRENTLY [ <replaceable class="parameter">boolean</replaceable> ]
|
||||
TABLESPACE <replaceable class="parameter">new_tablespace</replaceable>
|
||||
VERBOSE [ <replaceable class="parameter">boolean</replaceable> ]
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
@ -187,6 +188,15 @@ REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { IN
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>TABLESPACE</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Specifies that indexes will be rebuilt on a new tablespace.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>VERBOSE</literal></term>
|
||||
<listitem>
|
||||
@ -210,6 +220,14 @@ REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { IN
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">new_tablespace</replaceable></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The tablespace where indexes will be rebuilt.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
@ -294,7 +312,27 @@ REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { IN
|
||||
reindexed in a separate transaction. Those commands cannot be used inside
|
||||
a transaction block when working on a partitioned table or index.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When using the <literal>TABLESPACE</literal> clause with
|
||||
<command>REINDEX</command> on a partitioned index or table, only the
|
||||
tablespace references of the leaf partitions are updated. As partitioned
|
||||
indexes are not updated, it is recommended to separately use
|
||||
<command>ALTER TABLE ONLY</command> on them so as any new partitions
|
||||
attached inherit the new tablespace. On failure, it may not have moved
|
||||
all the indexes to the new tablespace. Re-running the command will rebuild
|
||||
all the leaf partitions and move previously-unprocessed indexes to the new
|
||||
tablespace.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If <literal>SCHEMA</literal>, <literal>DATABASE</literal> or
|
||||
<literal>SYSTEM</literal> is used with <literal>TABLESPACE</literal>,
|
||||
system relations are skipped and a single <literal>WARNING</literal>
|
||||
will be generated. Indexes on TOAST tables are rebuilt, but not moved
|
||||
to the new tablespace.
|
||||
</para>
|
||||
|
||||
<refsect2 id="sql-reindex-concurrently" xreflabel="Rebuilding Indexes Concurrently">
|
||||
<title>Rebuilding Indexes Concurrently</title>
|
||||
|
||||
|
Reference in New Issue
Block a user