Indexes can become a problem in many database applications that involve a high proportion of INSERT
/DELETE
commands. Just as tables can become bloated, so can indexes.
In the previous recipe, you saw that non-HOT updates can cause bloated indexes. Non-primary-key indexes are also prone to some bloat from normal INSERT
commands, as is common in most relational databases.
Autovacuum does not detect bloated indexes, nor does it do anything to rebuild indexes. So, we need to look at other ways to maintain indexes.
PostgreSQL supports commands that will rebuild indexes for you. The client utility, reindexdb
, allows you to execute the REINDEX
command in a convenient way from the operating system:
$ reindexdb
This executes the SQL REINDEX
command on every table in the default database. If you want to reindex all databases, then use the following:
$ reindexdb -a
That's what the manual says anyway. My experience is that most indexes don't need rebuilding, and even if...