agentleFS
mturacmturac/hermes-supercode-skills/skills/db-whisperer/SKILL.md

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."

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
  1. Very specific:

    Postgres: use EXPLAIN (ANALYZE, BUFFERS, VERBOSE) when safe

    line 24
  2. Very specific:

    MySQL: use EXPLAIN ANALYZE where available, otherwise EXPLAIN

    line 25
  3. Distinctive:

    Treat estimates, actual rows, loops, sort methods, and buffer reads as evidence, not decoration

    line 28
  4. Distinctive:

    Add composite indexes in equality-before-range order

    line 33
  5. Distinctive:

    Prefer covering indexes for hot read paths when write cost is acceptable

    line 34
  6. Distinctive:

    Avoid duplicate indexes and low-cardinality indexes that do not filter meaningfully

    line 35
  7. Very specific:

    Every migration needs an up path and a rollback down path

    line 40
  8. Distinctive:

    Avoid changing column types, primary keys, or nullability without a plan for locks, backfills, and application compatibility

    line 43
  9. Distinctive:

    Add application or migration code locally

    line 101
  10. Distinctive:

    Add indexes using engine-appropriate safe syntax when possible

    line 102
  11. Distinctive:

    Add rollback scripts for migrations

    line 103
  12. Distinctive:

    Update ORM query patterns to remove N+1 behavior

    line 104
  13. Distinctive:

    Document operational steps for replication, vacuum, or analyze tasks

    line 106
  14. Distinctive:

    Run the smallest relevant verification:

    line 130
  15. Distinctive:

    Run migration up and down on a local or staging database

    line 133
  16. Distinctive:

    Run affected application tests

    line 134
  17. Distinctive:

    Check query count tests for ORM changes

    line 135
  18. Distinctive:

    If verification cannot run, explain the missing database, fixture, or access and provide the exact command or query the user should run.

    line 140
  19. Distinctive:

    Remove tables, databases, or collections

    line 185
  20. Distinctive:

    Run irreversible migrations without a rollback script

    line 186
  21. Distinctive:

    Create indexes on tables larger than 1M rows because lock and write-load risks depend on engine and syntax

    line 191
  22. Very specific:

    Run EXPLAIN ANALYZE or equivalent against a user-approved query

    line 199
  23. Distinctive:

    Write migration scripts locally

    line 201
  24. Distinctive:

    Ask for engine/version if missing

    line 212
  25. Distinctive:

    Verify with before/after plan

    line 216
  26. Distinctive:

    Add nullable column first

    line 223
  27. Distinctive:

    Add application write path

    line 225
  28. Very specific:

    Add NOT NULL constraint in a later migration

    line 227
  29. Distinctive:

    Check database max connections and reserved admin slots

    line 237
  30. Distinctive:

    Add metrics for checkout wait time and connection usage

    line 239

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 ANALYZE where available, otherwise EXPLAIN
  • 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 WHERE clauses 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 up path and a rollback down path
  • 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/orders

For 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 queries

State 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:

  1. Capture baseline query plan or metrics
  2. Add application or migration code locally
  3. Add indexes using engine-appropriate safe syntax when possible
  4. Add rollback scripts for migrations
  5. Update ORM query patterns to remove N+1 behavior
  6. Tune pool settings only after matching them to process/thread topology
  7. 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 grows

4. 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 ANALYZE or 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:

  1. Ask for engine/version if missing
  2. Request or run the query plan
  3. Identify scan, join, sort, or cardinality problem
  4. Propose the smallest index or query rewrite
  5. Verify with before/after plan

New Column Migration

User: "Add a required column to users."

Response pattern:

  1. Add nullable column first
  2. Backfill in batches
  3. Add application write path
  4. Validate no nulls remain
  5. Add NOT NULL constraint in a later migration
  6. Include down migrations for every phase

Pool Exhaustion

User: "Connection pool exhausted."

Response pattern:

  1. Compare pool size to web workers, threads, and background jobs
  2. Find long transactions and leaked connections
  3. Check database max connections and reserved admin slots
  4. Tune pool and timeout values only after removing leaks
  5. Add metrics for checkout wait time and connection usage

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.