From fb726283b60572dd3390e3f96b85ab21ab3ccc6e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 20 Nov 2001 02:45:00 +0000 Subject: [PATCH] Expand description of how to use REINDEX. --- doc/src/sgml/ref/reindex.sgml | 111 ++++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/ref/reindex.sgml b/doc/src/sgml/ref/reindex.sgml index bcff1072a5..e6dfa4c5b6 100644 --- a/doc/src/sgml/ref/reindex.sgml +++ b/doc/src/sgml/ref/reindex.sgml @@ -1,5 +1,5 @@ @@ -15,7 +15,7 @@ Postgres documentation REINDEX - recover a corrupted system index + rebuild corrupted indexes @@ -49,6 +49,7 @@ REINDEX { TABLE | DATABASE | INDEX } name Recreate all system indexes of a specified database. + (User-table indexes are not included.) @@ -72,8 +73,10 @@ REINDEX { TABLE | DATABASE | INDEX } nameFORCE - Recreate indexes forcedly. Without this keyword REINDEX does - nothing unless target indexes are invalidated. + Force rebuild of system indexes. Without this keyword + REINDEX skips system indexes that are not marked invalid. + FORCE is irrelevant for REINDEX INDEX, or when reindexing + user indexes. @@ -114,11 +117,86 @@ REINDEX Description - REINDEX is used to recover corrupted system indexes. - In order to run REINDEX command, postmaster must be shut down and - stand-alone Postgres should be started instead with options -O and - -P (an option to ignore system indexes). Note that we couldn't rely - on system indexes for the recovery of system indexes. + REINDEX is used to rebuild corrupted indexes. + Although in theory this should never be necessary, in practice + indexes may become corrupted due to software bugs or hardware + failures. REINDEX provides a recovery method. + + + + If you suspect corruption of an index on a user table, you can + simply rebuild that index, or all indexes on the table, using + REINDEX INDEX or REINDEX TABLE. + + + + + 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. REINDEX acquires exclusive lock + on the table, while CREATE INDEX only locks out writes + not reads of the table. + + + + + 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 REINDEX INDEX, REINDEX TABLE, or + REINDEX DATABASE depending on how much you want to reconstruct. + If in doubt, use REINDEX DATABASE FORCE to force reconstruction + of all system indexes in the database. Then quit the standalone backend + and restart the postmaster. + + + + Since this is likely the only situation when most people will ever use + a standalone backend, some usage notes might be in order: + + + + + Start the backend with a command like + +postgres -D $PGDATA -O -P my_database + + Provide the correct path to the database area with + + + + + You can issue any SQL command, not only REINDEX. + + + + + + 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 psql. + Also, you won't have any of the conveniences of readline processing + (no command history, for example). + + + + + + To quit the backend, type EOF (control-D, usually). + + + + @@ -127,7 +205,7 @@ REINDEX Usage - Recreate the table mytable: + Recreate the indexes on the table mytable: REINDEX TABLE mytable; @@ -135,11 +213,18 @@ REINDEX - Some more examples: + Rebuild a single index: -REINDEX DATABASE my_database FORCE; -REINDEX INDEX my_index; + REINDEX INDEX my_index; + + + + + Rebuild all system indexes (this will only work in a standalone backend): + + + REINDEX DATABASE my_database FORCE;