Postgres performance optimization and best practices. Use when writing or reviewing SQL queries, designing schemas, configuring connection pooling, fixing N+1 queries, creating indexes, implementing row-level security, diagnosing slow queries with EXPLAIN ANALYZE, or optimizing database performance.
71
86%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Comprehensive performance optimization guide for Postgres. 31 rules across 8 categories, prioritized by impact — from critical (query performance, connection management) to incremental (advanced features).
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Query Performance | CRITICAL | query- |
| 2 | Connection Management | CRITICAL | conn- |
| 3 | Security & RLS | CRITICAL | security- |
| 4 | Schema Design | HIGH | schema- |
| 5 | Concurrency & Locking | MEDIUM-HIGH | lock- |
| 6 | Data Access Patterns | MEDIUM | data- |
| 7 | Monitoring & Diagnostics | LOW-MEDIUM | monitor- |
| 8 | Advanced Features | LOW | advanced- |
query-missing-indexes - Add indexes on WHERE and JOIN columnsquery-composite-indexes - Create composite indexes for multi-column queriesquery-covering-indexes - Use covering indexes to avoid table lookupsquery-partial-indexes - Use partial indexes for filtered queriesquery-index-types - Choose the right index type for your dataconn-pooling - Use connection pooling for all applicationsconn-limits - Set appropriate connection limitsconn-idle-timeout - Configure idle connection timeoutsconn-prepared-statements - Use prepared statements correctly with poolingsecurity-rls-basics - Enable Row Level Security for multi-tenant datasecurity-rls-performance - Optimize RLS policies for performancesecurity-privileges - Apply principle of least privilegeschema-data-types - Choose appropriate data typesschema-constraints - Add constraints safely in migrationsschema-primary-keys - Select optimal primary key strategyschema-foreign-key-indexes - Index foreign key columnsschema-partitioning - Partition large tables for better performanceschema-lowercase-identifiers - Use lowercase identifiers for compatibilitylock-short-transactions - Keep transactions short to reduce lock contentionlock-deadlock-prevention - Prevent deadlocks with consistent lock orderinglock-advisory - Use advisory locks for application-level lockinglock-skip-locked - Use SKIP LOCKED for non-blocking queue processingdata-n-plus-one - Eliminate N+1 queries with batch loadingdata-pagination - Use cursor-based pagination instead of OFFSETdata-batch-inserts - Batch INSERT statements for bulk datadata-upsert - Use UPSERT for insert-or-update operationsmonitor-explain-analyze - Use EXPLAIN ANALYZE to diagnose slow queriesmonitor-pg-stat-statements - Enable pg_stat_statements for query analysismonitor-vacuum-analyze - Maintain table statistics with VACUUM and ANALYZEadvanced-full-text-search - Use tsvector for full-text searchadvanced-jsonb-indexing - Index JSONB columns for efficient queryingEach rule file in references/ contains: explanation, incorrect/correct SQL examples, EXPLAIN output, and context. Read individual files as needed.
298fce7
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.