psql -d appdb -c "REINDEX DATABASE appdb;"

Category: Databases & SQL

psql -d appdb -c "REINDEX DATABASE appdb;"

Rebuild every index in a database

Rebuilds all indexes in the database, the full sweep after a major version change or serious bloat. It takes locks per relation as it goes; REINDEX DATABASE CONCURRENTLY avoids blocking writes.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.