REINDEX rebuilds an index using the data stored in the index's table, replacing the old copy of the index.
There are several scenarios in which REINDEX can be used:
An index build with the CONCURRENTLY option failed, leaving an "invalid" index.
Index reconstruction of the REINDEX DATABASE or SYSTEM type cannot be performed in transaction blocks.
1 | REINDEX { INDEX | TABLE | DATABASE | SYSTEM } name [ FORCE ]; |
1 2 | REINDEX { TABLE } name PARTITION partition_name [ FORCE ]; |
Recreates the specified index.
Recreates all indexes of the specified table. If the table has a secondary TOAST table, that is reindexed as well.
Recreates all indexes within the current database. Indexes on the shared system directory will also be processed. This form of REINDEX cannot be executed within a transaction block.
Recreates all indexes on system catalogs within the current database. Indexes on user tables are not processed.
Name of the specific index, table, or database to be reindexed. Index and table names can be schema-qualified.
REINDEX DATABASE and SYSTEM can create indexes for only the current database. Therefore, name must be the same as the current database name.
This is an obsolete option. It is ignored if specified.
Specifies the name of the partition or index partition to be reindexed.
Value range:
Index reconstruction of the REINDEX DATABASE or SYSTEM type cannot be performed in transaction blocks.
Rebuild a single index.
1 | REINDEX INDEX tpcds.tpcds_customer_index1; |
Rebuild all indexes on the tpcds.customer_t1 table.
1 | REINDEX TABLE tpcds.customer_t1; |