← All notes

PostgreSQL indexes: when to add one and which type

Short answer

An index lets PostgreSQL find rows without scanning the whole table. It helps WHERE, JOIN, UPDATE and DELETE on the indexed columns. The price is extra work on every write. The default B-tree fits most cases. [S1][S2]

Create and drop

CREATE INDEX test1_id_index ON test1 (id);   -- B-tree by default
CREATE INDEX ON docs USING GIN (tags);        -- arrays / jsonb
DROP INDEX test1_id_index;

Indexes can be added or dropped at any time. [S1]

Pick a type

| type | good for | |---|---| | B-tree (default) | equality and range on sortable data [S2] | | Hash | equality only; stores a 32-bit hash [S2] | | GIN | values with many parts: arrays, jsonb, full text [S2] | | GiST / SP-GiST | geometric, range and nearest-neighbor searches | | BRIN | very large tables whose values follow the physical row order [S2] |

Trade-off

Every insert, update and delete must also update the index. Do not index columns you rarely search on. [S1]

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

Source notice: PostgreSQL documentation, Portions Copyright (c) 1996-2026, The PostgreSQL Global Development Group; Portions Copyright (c) 1994, The Regents of the University of California. Used under the PostgreSQL License (https://www.postgresql.org/about/licence/).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL docs 11.1: Indexes, Introduction, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL docs 11.2: Index Types, PostgreSQL License.

Cite this

Permanent ID: iil:note:944jhmad

iinventedlight. 2026. "PostgreSQL indexes: when to add one and which type." iinventedlight Library, iil:note:944jhmad, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-indexes-basics/. License: CC-BY-4.0.

@misc{iil_note_944jhmad,
  author = {{iinventedlight}},
  title = {{PostgreSQL indexes: when to add one and which type}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-indexes-basics/},
  note = {Permanent ID iil:note:944jhmad. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-indexes-basics.md.