reindexdb: Usage, Options & Common CI Errors
reindexdb rebuilds one or more indexes to remove bloat or fix corruption.
reindexdb is a wrapper around REINDEX used to recover from index bloat or corruption. In CI the key choice is --concurrently to avoid taking a blocking lock on busy tables.
What it does
reindexdb connects to a server and runs REINDEX to rebuild indexes - by index, table, schema, database, or system catalogs. Rebuilding fixes corruption and reclaims space from bloated indexes.
Common usage
PGPASSWORD=secret reindexdb -h localhost -U postgres -d app
reindexdb -h localhost -U postgres -t users -d app
reindexdb -h db -U postgres --concurrently -d app
reindexdb -h localhost -U postgres -s public -d app # one schemaOptions
| Flag | What it does |
|---|---|
| -a / --all | Reindex every database |
| -s / --schema <name> | Reindex a schema |
| -t / --table <name> | Reindex a table |
| -i / --index <name> | Reindex a specific index |
| --concurrently | Rebuild without an exclusive write lock |
| -S / --system | Reindex system catalogs |
Common errors in CI
Plain REINDEX takes an ACCESS EXCLUSIVE lock that blocks reads and writes - use --concurrently (PostgreSQL 12+) so other steps are not stalled. "ERROR: REINDEX CONCURRENTLY cannot run inside a transaction block" means it was wrapped in a transaction. "ERROR: must be owner of ..." means the role lacks privileges on the index. A failed CONCURRENTLY rebuild can leave an INVALID index behind that must be dropped.