Rebuild index in PostgreSQL database REINDEX

Rebuild the index of tables, database, and schema in PostgreSQL

Rebuild index is building the index as a new one because it first drops and then creates an index. Rebuild index will fixed performance issues in many cases like in transactional tables which have a lot of insert/ update / delete DML operations which causes them to be fragmented So rebuild will create the index as a new one.

Check the indexes of the table

SELECT tablename, indexname FROM pg_indexes WHERE tablename='table_name';

Syntax to rebuild indexes:

REINDEX [ ( VERBOSE ) ] { INDEX | TABLE | SCHEMA | DATABASE | SYSTEM } name;

Rebuild the Index: Specify the name of the index you want to rebuild

 REINDEX INDEX index_name;

Rebuild all the indexes of a table:

REINDEX TABLE table_name;

Rebuild all the indexes present in a schema:

REINDEX SCHEMA schema_name;

Rebuild all the indexes in the database:

REINDEX DATABASE database_name;
This entry was posted in PostgreSQL on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply