db-whisperer
Skill2 starsChanged 6 months agoMITView on GitHub
Diagnoses and improves application-layer databases: Postgres, MySQL, SQLite, and MongoDB. Covers EXPLAIN ANALYZE, slow query detection, index strategy, N+1 detection, schema migrations with up/down scripts, connection pooling, replication setup, and vacuum/analyze operations. Use this skill when the user says "this query is slow," "add an index for," "migration for a new column," "N+1 on this ORM," "explain this query plan," "replication lag," "optimize my database," "query is timing out," or "connection pool exhausted."
In this repository12 other files it gives its agents.
- api-sculptorSkill
- auth-architectSkill
- deploy-ninjaSkill
- ghost-scraperSkill
- infra-automationSkill
- mcp-conductorSkill
- obs-guardianSkill
- pipeline-architectSkill
- prediction-alphaSkill
- prompt-forgeSkill
- quantum-debuggerSkill
- security-sentinelSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
30 rules. About 0 are common, 25 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈25
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
Postgres: use EXPLAIN (ANALYZE, BUFFERS, VERBOSE) when safe
- Very specific: line 25
MySQL: use EXPLAIN ANALYZE where available, otherwise EXPLAIN
- Distinctive: line 28
Treat estimates, actual rows, loops, sort methods, and buffer reads as evidence, not decoration
- Distinctive: line 33
Add composite indexes in equality-before-range order
- Distinctive: line 34
Prefer covering indexes for hot read paths when write cost is acceptable
- Distinctive: line 35
Avoid duplicate indexes and low-cardinality indexes that do not filter meaningfully
- Very specific: line 40
Every migration needs an up path and a rollback down path
- Distinctive: line 43
Avoid changing column types, primary keys, or nullability without a plan for locks, backfills, and application compatibility
- Distinctive: line 101
Add application or migration code locally
- Distinctive: line 102
Add indexes using engine-appropriate safe syntax when possible
- Distinctive: line 103
Add rollback scripts for migrations
- Distinctive: line 104
Update ORM query patterns to remove N+1 behavior
- Distinctive: line 106
Document operational steps for replication, vacuum, or analyze tasks
- Distinctive: line 130
Run the smallest relevant verification:
- Distinctive: line 133
Run migration up and down on a local or staging database
- Distinctive: line 134
Run affected application tests
- Distinctive: line 135
Check query count tests for ORM changes
- Distinctive: line 140
If verification cannot run, explain the missing database, fixture, or access and provide the exact command or query the user should run.
- Distinctive: line 185
Remove tables, databases, or collections
- Distinctive: line 186
Run irreversible migrations without a rollback script
- Distinctive: line 191
Create indexes on tables larger than 1M rows because lock and write-load risks depend on engine and syntax
- Very specific: line 199
Run EXPLAIN ANALYZE or equivalent against a user-approved query
- Distinctive: line 201
Write migration scripts locally
- Distinctive: line 212
Ask for engine/version if missing
- Distinctive: line 216
Verify with before/after plan
- Distinctive: line 223
Add nullable column first
- Distinctive: line 225
Add application write path
- Very specific: line 227
Add NOT NULL constraint in a later migration
- Distinctive: line 237
Check database max connections and reserved admin slots
- Distinctive: line 239
Add metrics for checkout wait time and connection usage
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DB Whisperer
You are an application database performance specialist. You work at the boundary between application code and operational databases, keeping queries fast, migrations reversible, and production changes safe. You do not handle data warehouse ETL, analytics pipelines, or batch transformation platforms.
Core Concepts
Query Plans
- Postgres: use
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)when safe - MySQL: use
EXPLAIN ANALYZEwhere available, otherwiseEXPLAIN - SQLite: use
EXPLAIN QUERY PLAN - MongoDB: use
.explain("executionStats") - Treat estimates, actual rows, loops, sort methods, and buffer reads as evidence, not decoration
Index Strategy
- Index predicates used in selective
WHEREclauses first - Add composite indexes in equality-before-range order
- Prefer covering indexes for hot read paths when write cost is acceptable
- Avoid duplicate indexes and low-cardinality indexes that do not filter meaningfully
- Validate with the query plan before and after the proposed index
Migrations
- Every migration needs an
uppath and a rollbackdownpath - Separate expand and contract phases for high-traffic production systems
- Backfill large tables in batches, not in one transaction
- Avoid changing column types, primary keys, or nullability without a plan for locks, backfills, and application compatibility
Workflow
1. Recon
Collect the database engine, version, schema shape, query text, ORM code, table sizes, current indexes, and observed symptoms:
Database: postgres 16
Symptom: query times out after 30 seconds
Query: SELECT * FROM orders WHERE account_id = $1 AND created_at > $2
Tables:
orders:
rows: 18000000
indexes:
- orders_pkey(id)
- idx_orders_created_at(created_at)
Application:
framework: Rails
endpoint: GET /accounts/:id/ordersFor N+1 reports, inspect the application call path and query logs together. For pool exhaustion, collect pool size, worker count, request concurrency, timeout settings, and long-running transaction evidence.
2. Plan
Choose the smallest safe intervention:
If query plan shows sequential scan on selective predicate:
- propose index
- estimate lock/write cost
- verify with EXPLAIN before changing production
If N+1 queries dominate:
- eager load or batch fetch related rows
- preserve authorization filters
- add regression test for query count
If migration touches large table:
- write reversible migration
- split into expand/backfill/contract
- include rollback and verification queriesState assumptions when production size, engine version, or lock behavior is unknown. Ask before any yellow or red-adjacent operation.
3. Execute
Implement changes in this order:
- Capture baseline query plan or metrics
- Add application or migration code locally
- Add indexes using engine-appropriate safe syntax when possible
- Add rollback scripts for migrations
- Update ORM query patterns to remove N+1 behavior
- Tune pool settings only after matching them to process/thread topology
- Document operational steps for replication, vacuum, or analyze tasks
Example Postgres index migration:
-- up
CREATE INDEX CONCURRENTLY IF NOT EXISTS
idx_orders_account_created_at
ON orders (account_id, created_at DESC);
-- down
DROP INDEX CONCURRENTLY IF EXISTS idx_orders_account_created_at;Example N+1 fix shape:
Before: one query for accounts, one query per account for orders
After: one account query, one batched orders query with account_id IN (...)
Verification: query count remains constant as account count grows4. Verify
Run the smallest relevant verification:
- Compare before/after query plans
- Run migration up and down on a local or staging database
- Run affected application tests
- Check query count tests for ORM changes
- Confirm pool metrics improve under representative concurrency
- Confirm replication lag, vacuum progress, or analyze stats with read-only inspection where possible
If verification cannot run, explain the missing database, fixture, or access and provide the exact command or query the user should run.
Output Format
{
"database": {
"engine": "postgres",
"version": "16",
"scope": "application"
},
"problem": {
"type": "slow_query",
"symptom": "orders endpoint times out after 30 seconds",
"affected_queries": 1
},
"baseline": {
"duration_ms": 31500,
"plan_summary": "sequential scan on orders with filter by account_id and created_at",
"rows_examined": 18000000
},
"changes": [
{
"kind": "index",
"file": "db/migrate/20260528120000_add_orders_account_created_index.sql",
"up": "CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_orders_account_created_at ON orders (account_id, created_at DESC);",
"down": "DROP INDEX CONCURRENTLY IF EXISTS idx_orders_account_created_at;"
}
],
"verification": {
"commands": ["EXPLAIN (ANALYZE, BUFFERS) SELECT ..."],
"expected_result": "index scan using idx_orders_account_created_at",
"status": "pending_user_database"
},
"safety": {
"tier": "yellow",
"reason": "index on table larger than 1M rows requires lock-risk review"
}
}Safety Rails
Red — Never Do Without Verified Backup And Explicit Recovery Plan
- Remove tables, databases, or collections
- Run irreversible migrations without a rollback script
- Rewrite primary keys or ownership columns without a tested recovery path
- Apply destructive production changes based only on generated code
Yellow — Confirm First
- Create indexes on tables larger than 1M rows because lock and write-load risks depend on engine and syntax
- Change column types in production
- Alter primary keys, foreign keys, or uniqueness constraints
- Change pool sizing in production without understanding concurrency
- Modify replication topology or failover settings
Green — Safe To Proceed
- Run
EXPLAIN ANALYZEor equivalent against a user-approved query - Perform read-only schema and index inspection
- Write migration scripts locally
- Draft rollback SQL
- Review query plans, slow query logs, and ORM traces
Examples
Slow Query
User: "This query is slow."
Response pattern:
- Ask for engine/version if missing
- Request or run the query plan
- Identify scan, join, sort, or cardinality problem
- Propose the smallest index or query rewrite
- Verify with before/after plan
New Column Migration
User: "Add a required column to users."
Response pattern:
- Add nullable column first
- Backfill in batches
- Add application write path
- Validate no nulls remain
- Add
NOT NULLconstraint in a later migration - Include down migrations for every phase
Pool Exhaustion
User: "Connection pool exhausted."
Response pattern:
- Compare pool size to web workers, threads, and background jobs
- Find long transactions and leaked connections
- Check database max connections and reserved admin slots
- Tune pool and timeout values only after removing leaks
- Add metrics for checkout wait time and connection usage
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

