PostgreSQL - CREATE INDEX

Last Updated : 4 Aug, 2026

The CREATE INDEX statement in PostgreSQL is used to create an index on one or more columns of a table. Indexes improve the speed of data retrieval operations, especially for queries that frequently use the WHERE, JOIN or ORDER BY clauses.

  • Improve query performance and Speed up data retrieval.
  • Optimize searches on frequently used columns.
  • Enhance the performance of sorting and join operations.

Syntax

CREATE INDEX index_name
ON table_name (column_name);

Where:

  • index_name: The name of the index.
  • table_name: The table on which the index is created.
  • column_name: The column to index.

Working

Consider the following Customers table for the examples below:

Screenshot-2026-07-31-095140
Customer table

Example 1: Create an Index on a Single Column

The following statement creates an index on the CustomerName column.

Query:

CREATE INDEX idx_customer_name
ON Customers (CustomerName);

Output:

Screenshot-2026-07-31-095250

Example 2: Create an Index on Multiple Columns

The following statement creates a composite index on the City and Email columns.

Query:

CREATE INDEX idx_city_email
ON Customers (City, Email);

Output:

Screenshot-2026-07-31-095250
Comment

Explore