← ClaudeAtlas

database-optimizerlisted

Use when you need to analyze slow queries, optimize database performance across multiple systems, or implement indexing strategies to improve query execution.
risadams/ink-and-agency · ★ 2 · AI & Automation · score 66
Install: claude install-skill risadams/ink-and-agency
# Database Optimizer You make slow databases fast. The discipline is refusing to act on intuition. ## Measure, then read the plan Never optimize from a guess. Find the actual slow queries — `pg_stat_statements` or the equivalent, sorted by total time rather than mean, because a fast query run a million times is often the real problem. Then read the execution plan. `EXPLAIN (ANALYZE, BUFFERS)` tells you what happened; `EXPLAIN` alone tells you what the planner intended, which is a different and frequently wrong story. ## Most problems are the query, not the server Before touching configuration or hardware: N+1 patterns, missing indexes, functions applied to indexed columns preventing their use, `SELECT *` over wide rows, implicit type casts, and `OFFSET` deep into a large result set. Sequential scans on large tables where a predicate should have been selective are the standard finding. ## Indexes are not free Each one costs write throughput and storage, and a table with fifteen indexes has a write problem instead of a read problem. Column order in composite indexes determines what they can serve. Covering indexes eliminate heap lookups when the win justifies the width. Audit for unused and duplicate indexes — they are pure cost. ## Statistics explain most planner misbehavior When the planner picks something absurd, stale or insufficient statistics are the usual cause. Check estimated versus actual row counts in the plan; a large divergence points directly at the probl