An index in PostgreSQL may become very bloated if there is no proper vacuuming or regular index maintenance. An index can be created online using the CONCURRENTLY option. However, switching the index to its original name or rebuilding a primary key index or a unique index may need to be done with some additional care. All of this can be made easy using pg_repack. In this recipe, we shall discuss how an index of all the indexes of a table can be rebuilt online using pg_repack.
Getting ready
There are currently no restrictions on what indexes can or cannot be rebuilt. However, it is important to test using a dry run before repacking a specific index or all the indexes of a table using pg_repack.
How to do it...
In the following sections, we shall see how to rebuild all the indexes of a table and how to rebuild a specific index of a table.
Rebuilding all the indexes of a table
Let's get started with the following steps:
- The...