REINDEX recreates one or more existing indexes using the current index definition. The command scans the underlying table (or catalog) and writes a brand-new copy of the index, then swaps it in place of the old one. This removes logical bloat that accumulates after many UPDATE or DELETE operations, shrinking on-disk size and speeding up future lookups.REINDEX can target a single index, all indexes on a table, an entire schema, or even the whole database/system catalogs. Each subtype acquires different locks:- INDEX / TABLE requires an ACCESS EXCLUSIVE lock on the index or table.- SCHEMA / DATABASE / SYSTEM hold exclusive locks on each object as it is processed.Use the CONCURRENTLY option to keep the table readable during the rebuild, at the cost of a longer run time and higher temporary disk usage. CONCURRENTLY cannot be combined with SYSTEM or executed inside a transaction block.Caveats:1. Requires disk space roughly equal to the existing index size.2. Large tables may experience write amplification on replication.3. Fails if another session holds a conflicting lock.4. In PostgreSQL, only B-tree, GiST, GIN and SP-GiST indexes support concurrent rebuild.Because REINDEX copies data rather than reorganizing it in place, it guarantees a fully optimized structure once complete.
object_type
(enum) - INDEX, TABLE, SCHEMA, DATABASE, or SYSTEM indicating the scope of rebuildname
(ident) - Name of the index, table, schema, or database to rebuildCONCURRENTLY
(flag) - Rebuild without blocking reads; not allowed for SYSTEMVERBOSE
(flag) - Emit progress messages to the clientVACUUM, ANALYZE, CREATE INDEX, ALTER INDEX, CLUSTER, VACUUM FULL
PostgreSQL 7.2
Use REINDEX when an index is heavily bloated or shows corruption. VACUUM cleans up dead tuples but cannot rewrite index pages.
Without CONCURRENTLY, REINDEX acquires an ACCESS EXCLUSIVE lock and blocks all access to the target object. The CONCURRENTLY option keeps reads running but still pauses writes briefly.
It runs slower than a standard REINDEX because it builds a new index in the background and validates it twice. Duration scales with table size and system I/O throughput.
Yes, if you monitor disk space and pick low-traffic windows. Prefer the CONCURRENTLY option for large, read-heavy tables.