Speed containment queries on JSONB data.

Section: PostgreSQL index types

GIN index on JSONB

sql
sql
CREATE INDEX idx_events_payload_gin ON events USING GIN (payload jsonb_path_ops);
Explanation

GIN is often used for composite or document-like structures such as JSONB and arrays.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing PostgreSQL index types
B-tree index
Default choice for equality, ranges, and ordering.
OpenIn sheetsqlsame section
BRIN index for large append-heavy tables
Use BRIN when physical order correlates with query ranges.
OpenIn sheetsqlsame section
Expression index
Index the result of an expression used in predicates.
OpenIn sheetsqlsame section
Partial index
Index only the rows a hot query actually needs.
OpenIn sheetsqlsame section
Create index concurrently
Reduce blocking on busy tables.
OpenIn sheetsqlsame section
Explain with runtime stats
Inspect actual execution behavior.
OpenIn sheetsql1 tag match