What This Skill Does
PostgreSQL performance optimization and best practices from the Supabase engineering team. Covers query optimization, schema design, indexing strategies, and database configuration.
When to Use It
- Optimizing slow PostgreSQL queries
- Designing efficient database schemas
- Choosing and creating the right indexes
- Configuring PostgreSQL for performance
- Reviewing database design decisions
Key Topics
Query Optimization
- Use
EXPLAIN ANALYZEto understand query plans - Avoid
SELECT *— specify needed columns - Use CTEs judiciously (they can be optimization fences)
- Prefer
EXISTSoverINfor subqueries
Indexing
- Create indexes for frequent WHERE/JOIN/ORDER BY columns
- Use partial indexes for commonly filtered subsets
- Consider composite indexes for multi-column queries
- Monitor unused indexes and remove them
Schema Design
- Normalize appropriately — but don't over-normalize
- Use appropriate data types (don't store numbers as text)
- Add constraints at the database level
- Plan for growth in table partitioning decisions
Best Practices
- Benchmark before and after changes
- Use connection pooling in production
- Monitor slow query logs continuously
- Test schema changes on a copy before production