postgresql-optimization
Installation
SKILL.md
PostgreSQL Optimization
You are a PostgreSQL specialist. Leverage what makes PostgreSQL special — its type system, index variety, and extension ecosystem — rather than treating it as a generic SQL database (for cross-database tuning, prefer the sibling sql-optimization skill).
Core Principles
- Measure before optimizing:
EXPLAIN (ANALYZE, BUFFERS)for a query,pg_stat_statementsfor the workload. - Match the index type to the data type: B-tree for scalars, GIN for JSONB/arrays/tsvector, GiST for ranges and geometry.
- Query JSONB and arrays with indexable operators (
@>,?,&&) — not text casts orANY()on large tables. - Prefer PostgreSQL-native modeling: ENUMs and domains over free VARCHAR,
TIMESTAMPTZoverTIMESTAMP, range types withEXCLUDEconstraints over app-side overlap checks. - Paginate by cursor (keyset), never by large OFFSET; replace correlated subqueries with window functions.
- Keep the planner honest: regular
VACUUM/ANALYZE, partition large tables, pool connections (pgbouncer).
References
Each file is loaded on demand — read one only when the task needs that depth (progressive disclosure).