Postgres indexes that actually matter
Three patterns that fix most slow queries.
When an app gets slow, the cause is usually a few queries. Check indexes before reaching for caching.
Composite indexes
An index on (account_id, created_at) serves account-specific sorting well.
CREATE INDEX CONCURRENTLY idx_events_account_created
ON events (account_id, created_at DESC);Partial indexes
If almost all rows are archived, index only active rows.