Skip to content
Latchkey

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

Terminal
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 schema

Options

FlagWhat it does
-a / --allReindex every database
-s / --schema <name>Reindex a schema
-t / --table <name>Reindex a table
-i / --index <name>Reindex a specific index
--concurrentlyRebuild without an exclusive write lock
-S / --systemReindex 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →