EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PostgreSQL REINDEX

Home » Data Science » Data Science Tutorials » PostgreSQL Tutorial » PostgreSQL REINDEX

PostgreSQL REINDEX

Introduction to PostgreSQL REINDEX

To reconstruct one or more indexes, we generally use the PostgreSQL REINDEX statement. Sometimes due to software problems or bugs or some hardware failures, the indexes got corrupted; in such cases, we can use this statement to recover the index. We can recreate the index for TABLE, SCHEMA, DATABASE, or SYSTEM DATABASE and recreate the INDEX. The PostgreSQL REINDEX statement first drops all indexes and then creates all, which means it builds all indexes from scratch. The PostgreSQL REINDEX statement uses locking mechanisms to reconstruct the contents of the index.

Syntax of PostgreSQL REINDEX

Consider the following syntax to understand the statements:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

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

Explanation of PostgreSQL REINDEX

  • VERBOSE: This keyword is optional. The statement shows the progress report when the VERBOSE is defined while indexes being reindexed.
  • INDEX: Reconstruct the defined index.
  • TABLE: Reconstruct all indexes of the defined table.
  • DATABASE: Reconstruct all indexes of the defined database.
  • SYSTEM: Reconstruct all indexes on the system of the defined database.
  • name: This field defines the name of the index, table, database, or schema.

We can recreate index for TABLE, SCHEMA, DATABASE or INDEX.

Let’s understand the syntax for each of them as follows:

1. Recreate a Single Index.

REINDEX INDEX index_name;

2. Recreate all the indexes of a table.

REINDEX TABLE table_name;

3. Recreate all indices in a schema.

REINDEX SCHEMA schema_name;

4. Recreate all indices in a particular database.

REINDEX DATABASE database_name;

5. Recreate all indices in a system database.

REINDEX SYSTEM database_name;

How PostgreSQL REINDEX Works?

It drops and recreates of the indexes, which means it rebuilds all indexes from scratch. The statement uses locking mechanisms to recreate the indexes.

To use the REINDEX statement, we need to the owner of the INDEX or TABLE or DATABASE. Superusers can use the PostgreSQL REINDEX statement with anything.

Examples to Implement

Below are the examples of PostgreSQL REINDEX:

Example #1 – Recreate a Single Index

Consider the following statement where we need to define the index name after the PostgreSQL REINDEX INDEX clause; consider we have an index of name student_index, then we can recreate it using the PostgreSQL REINDEX statement.

Query:

REINDEX INDEX student_index;

Output:

PostgreSQL REINDEX Example 1

Example #2 – Recreate all the Indexes of a Table

Consider the following statement where we need to define the table name after the REINDEX TABLE clause. Consider we have a table of name student_table, then we can recreate it’s all indexes by using the PostgreSQL REINDEX statement.

Query:

REINDEX TABLE student_table;

Output:

PostgreSQL REINDEX Example 2

Example #3 – Recreate all Indices in a Schema

Consider the following statement where we need to define the schema name after the REINDEX SCHEMA clause. Consider we have a schema of name student_schema, then we can recreate it’s all indexes by using the PostgreSQL REINDEX statement.

Query:

REINDEX SCHEMA student_schema;

Output:

PostgreSQL REINDEX Example 3

Example #4 – Recreate all Indices in a Particular Database

Consider the following statement where we need to define the database name after the PostgreSQL REINDEX DATABASE clause. Consider we have a database of name student_database, then we can recreate it’s all indexes by using the REINDEX statement.

Query:

REINDEX DATABASE student_database;

Output:

Indices Example 4

Example #5 – Recreate all Indices in a System Database

Consider the following statement where we need to define the database name after the PostgreSQL REINDEX SYSTEM clause. Consider we have a system database of name system_db, then we can recreate all indexes by using the REINDEX statement.

Popular Course in this category
PostgreSQL Course (2 Courses, 1 Project)2 Online Courses | 1 Hands-on Project | 7+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (2,948 ratings)
Course Price

View Course

Related Courses

Query:

REINDEX SYSTEM system_db;

Output:

Recreate all indices Example 5

Recommended Articles

This is a guide to PostgreSQL REINDEX. Here we discuss the Introduction to PostgreSQL REINDEX and the practical examples and different subquery expressions. You can also go through our suggested articles to learn more –

  1. How to Notify Works in PostgreSQL?
  2. Introduction to PostgreSQL Timestamp
  3. PostgreSQL NOW() | How to Work?
  4. PostgreSQL RANDOM | Examples

PostgreSQL Course (2 Courses, 1 Project)

2 Online Courses

1 Hands-on Project

7+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PostgreSQL Tutorial
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL log_statement
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - PostgreSQL Course (2 Courses, 1 Project) Learn More