Commit fb726283 authored by Tom Lane's avatar Tom Lane

Expand description of how to use REINDEX.

parent 933761e7
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/reindex.sgml,v 1.4 2001/09/03 12:57:50 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/reindex.sgml,v 1.5 2001/11/20 02:45:00 tgl Exp $
Postgres documentation Postgres documentation
--> -->
...@@ -15,7 +15,7 @@ Postgres documentation ...@@ -15,7 +15,7 @@ Postgres documentation
REINDEX REINDEX
</refname> </refname>
<refpurpose> <refpurpose>
recover a corrupted system index rebuild corrupted indexes
</refpurpose> </refpurpose>
</refnamediv> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
...@@ -49,6 +49,7 @@ REINDEX { TABLE | DATABASE | INDEX } <replaceable class="PARAMETER">name</replac ...@@ -49,6 +49,7 @@ REINDEX { TABLE | DATABASE | INDEX } <replaceable class="PARAMETER">name</replac
<listitem> <listitem>
<para> <para>
Recreate all system indexes of a specified database. Recreate all system indexes of a specified database.
(User-table indexes are not included.)
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -72,8 +73,10 @@ REINDEX { TABLE | DATABASE | INDEX } <replaceable class="PARAMETER">name</replac ...@@ -72,8 +73,10 @@ REINDEX { TABLE | DATABASE | INDEX } <replaceable class="PARAMETER">name</replac
<term>FORCE</term> <term>FORCE</term>
<listitem> <listitem>
<para> <para>
Recreate indexes forcedly. Without this keyword REINDEX does Force rebuild of system indexes. Without this keyword
nothing unless target indexes are invalidated. <command>REINDEX</> skips system indexes that are not marked invalid.
FORCE is irrelevant for <command>REINDEX INDEX</>, or when reindexing
user indexes.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -114,11 +117,86 @@ REINDEX ...@@ -114,11 +117,86 @@ REINDEX
Description Description
</title> </title>
<para> <para>
<command>REINDEX</command> is used to recover corrupted system indexes. <command>REINDEX</command> is used to rebuild corrupted indexes.
In order to run REINDEX command, postmaster must be shut down and Although in theory this should never be necessary, in practice
stand-alone Postgres should be started instead with options -O and indexes may become corrupted due to software bugs or hardware
-P (an option to ignore system indexes). Note that we couldn't rely failures. <command>REINDEX</command> provides a recovery method.
on system indexes for the recovery of system indexes. </para>
<para>
If you suspect corruption of an index on a user table, you can
simply rebuild that index, or all indexes on the table, using
<command>REINDEX INDEX</command> or <command>REINDEX TABLE</command>.
</para>
<note>
<para>
Another approach to dealing with a corrupted user-table index is
just to drop and recreate it. This may in fact be preferable if
you would like to maintain some semblance of normal operation on
the table meanwhile. <command>REINDEX</> acquires exclusive lock
on the table, while <command>CREATE INDEX</> only locks out writes
not reads of the table.
</para>
</note>
<para>
Things are more difficult if you need to recover from corruption of an
index on a system table. In this case it's important for the backend
doing the recovery to not have used any of the suspect indexes itself.
(Indeed, in this sort of scenario you may find that backends are
crashing immediately at startup, due to reliance on the corrupted
indexes.) To recover safely, the postmaster must be shut down and a
stand-alone Postgres backend must be started instead, giving it
the command-line options -O and -P (these options allow system table
modifications and prevent use of system indexes, respectively). Then
issue <command>REINDEX INDEX</>, <command>REINDEX TABLE</>, or
<command>REINDEX DATABASE</> depending on how much you want to reconstruct.
If in doubt, use <command>REINDEX DATABASE FORCE</> to force reconstruction
of all system indexes in the database. Then quit the standalone backend
and restart the postmaster.
</para>
<para>
Since this is likely the only situation when most people will ever use
a standalone backend, some usage notes might be in order:
<itemizedlist>
<listitem>
<para>
Start the backend with a command like
<screen>
<userinput>postgres -D $PGDATA -O -P my_database</userinput>
</screen>
Provide the correct path to the database area with <option>-D</>, or
make sure that the environment variable <envar>PGDATA</> is set.
Also specify the name of the particular database you want to work in.
</para>
</listitem>
<listitem>
<para>
You can issue any SQL command, not only <command>REINDEX</>.
</para>
</listitem>
<listitem>
<para>
Be aware that the standalone backend treats newline as the command
entry terminator, not semicolon; you can't continue commands across
lines, as you can in <application>psql</>.
Also, you won't have any of the conveniences of readline processing
(no command history, for example).
</para>
</listitem>
<listitem>
<para>
To quit the backend, type EOF (control-D, usually).
</para>
</listitem>
</itemizedlist>
</para> </para>
</refsect1> </refsect1>
...@@ -127,7 +205,7 @@ REINDEX ...@@ -127,7 +205,7 @@ REINDEX
Usage Usage
</title> </title>
<para> <para>
Recreate the table <literal>mytable</literal>: Recreate the indexes on the table <literal>mytable</literal>:
<programlisting> <programlisting>
REINDEX TABLE mytable; REINDEX TABLE mytable;
...@@ -135,11 +213,18 @@ REINDEX ...@@ -135,11 +213,18 @@ REINDEX
</para> </para>
<para> <para>
Some more examples: Rebuild a single index:
<programlisting>
REINDEX INDEX my_index;
</programlisting>
</para>
<para>
Rebuild all system indexes (this will only work in a standalone backend):
<programlisting> <programlisting>
REINDEX DATABASE my_database FORCE; REINDEX DATABASE my_database FORCE;
REINDEX INDEX my_index;
</programlisting> </programlisting>
</para> </para>
</refsect1> </refsect1>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment