Also available: Markdown version · llms.txt · full site content
Database
Indexes
Speed up the queries your app actually runs. Create btree, hash, GIN, GiST, SP-GiST, and BRIN indexes on public tables — single-column, composite, expression, or partial.
Choosing a method
| Method | Good for |
|---|---|
btree | Equality and range queries, sorting — the default and the only unique-capable method |
hash | Equality-only lookups |
gin | jsonb containment, arrays, full-text search |
gist | Geometry, ranges, nearest-neighbour search |
spgist | Partitioned data like points and text prefixes |
brin | Very large tables whose physical order matches the column (e.g. timestamps) |
The Indexes screen lists every index in the public schema with its method, columns or expression, uniqueness, and size on disk.
Composite, expression, and partial indexes
- Composite: pick up to 16 columns, each with ASC/DESC and optional NULLS FIRST/LAST. Column order matters — put the most-filtered column first.
- Expression: index a computed value, e.g.
lower(email), when your queries filter on that expression. - Partial: add a WHERE filter, e.g.
status = 'active', to index only the rows you query. - Unique: btree only; enforces uniqueness like a constraint.
CREATE INDEX customers_plan_name ON public.customers (plan, name);
CREATE INDEX customers_email_lower ON public.customers (lower(email));
CREATE INDEX customers_active ON public.customers (owner_id)
WHERE status = 'active';
CREATE UNIQUE INDEX customers_email_unique ON public.customers (email);Constraint-backed indexes are protected
- Primary keys and unique constraints own their indexes. The screen marks them and refuses to drop them — dropping the index would drop the constraint’s enforcement.
- Ordinary indexes can be dropped at any time; queries fall back to sequential scans.
- Every index costs write speed and storage. Watch the size column and drop indexes your queries no longer use.