Skip to content
Development
Skill

/db-optimization

Use when the bottleneck is database-shaped — slow queries, lock timeouts, connection exhaustion, N+1 patterns, index questions, schema migrations on hot tables. Evidence-first DB playbook for PostgreSQL, MySQL/MariaDB, MongoDB, and Redis backing the db-performance-tuner agent.

From plugin
hydraia
852 skills27 agents17 commands6 hooks

Claude Code

$ npx -y skills add jdanigo/hydraia --skill db-optimization --agent claude-code

SKILL.md

db-optimization.SKILL.md
name: db-optimization
description: Use when the bottleneck is database-shaped — slow queries, lock timeouts, connection exhaustion, N+1 patterns, index questions, schema migrations on hot tables. Evidence-first DB playbook for PostgreSQL, MySQL/MariaDB, MongoDB, and Redis backing the db-performance-tuner agent.

DB Optimization — EXPLAIN before you touch anything

Playbook for the DB half of the Hydraia perf route. The `db-performance-tuner` agent does the diagnosis; this skill sets the rules the route runs under.

<HARD-RULES>

  • Read-first: no change is proposed without its EXPLAIN plan, stat, or code evidence. Live DB unavailable → code/schema inference only, tagged UNVERIFIED, with the confirming commands listed for the human.
  • All write-shaped operations (create index, schema change, config change) are PLAN TASKS — reviewed, gated, never executed by a diagnosis agent.
  • Destructive or blocking operations (table rewrites, long locks) are flagged for explicit human approval in the plan; prefer and name the online variant per engine: `CREATE INDEX CONCURRENTLY` (Postgres), `ALGORITHM=INPLACE, LOCK=NONE` (MySQL), rolling index builds (Mongo).
  • Schema changes on live tables follow EXPAND-CONTRACT, no exceptions.
  • Redact literal data values from any plan/log excerpt that lands in a committed artifact.

</HARD-RULES>

Expand-contract migration protocol

1. **Expand:** add the new column/table/index alongside the old — additive, backward-compatible, online. 2. **Dual-write + backfill:** application writes both shapes; backfill history in batches (bounded, throttled, resumable). 3. **Switch reads** to the new shape behind a verified flag; watch metrics. 4. **Contract:** only after a full bake period, remove the old shape in a later release. Contract is its own plan task, never bundled with expand.

Index design guidance

  • Composite order: equality columns first, then range, then sort — match the query, not intuition.
  • Covering indexes to eliminate lookups for hot read paths; weigh write amplification (every index taxes every write).
  • Partial/filtered indexes for skewed predicates (`WHERE deleted_at IS NULL`).
  • Hunt UNUSED indexes too (`pg_stat_user_indexes`, `sys.schema_unused_indexes`) — dropping one is also an optimization.
  • The index is not always the answer: sometimes it is the query shape, the schema, or the caller (N+1, missing cache).

N+1 patterns per ORM family

  • Detection: a loop in code + per-iteration query in the log/profile. The agent cites the code location.
  • Fix families: eager loading (`include`/`select_related`/`prefetch_related`/`preload`), query batching (`IN` lists), dataloader pattern (GraphQL), denormalized read models for hot aggregates.

Pooling guidance

  • Pool size starts near `connections = cores * 2 + effective_spindles` (HikariCP heuristic) — not hundreds; queueing beats connection thrash.
  • Always set: acquisition timeout, idle timeout, max lifetime. Connection churn (open/close per request) is itself a finding.

Per-engine evidence commands

See the db-performance-tuner agent definition for the full read-only evidence list per engine (EXPLAIN variants, stat views, lock views, SLOWLOG). This skill and that agent must stay in sync — update both or neither.

Read more
@jdanigo
Ships withhydraia

An agentic development harness for Claude Code. **One command runs the entire feature pipeline** — it collaborates with you on the design, then builds autonomously: plan, execute, double-review, and verify.

852 skills27 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
8
Star history of jdanigo/hydraia on GitHub, a chart by star-history.com

Other skills on hydraia.

hydraia

hydraia

Use whenever the user asks to build, add, implement, or change a feature or functionality — or brings a user story or ticket to…

@jdanigo@jdanigoInstall Skill
adr

adr

Use when a design decision is made that is expensive to reverse, affects multiple components, or rejects a plausible alternative…

@jdanigo@jdanigoInstall Skill
agency-tier-ui

agency-tier-ui

Teaches the AI to design like a high-end agency. Defines the exact fonts, spacing, shadows, card structures, and animations that…

@jdanigo@jdanigoInstall Skill
api-design

api-design

Use when designing or reviewing an API surface — REST, GraphQL, or gRPC. Contract-first methodology: the contract artifact…

@jdanigo@jdanigoInstall Skill
banner-design

banner-design

Design banners for social media, ads, website heroes, creative assets, and print. Multiple art direction options with…

@jdanigo@jdanigoInstall Skill
brainstorming

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior.…

@jdanigo@jdanigoInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills11d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc13d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react2d252k
@facebook@facebookInstall Skill

Questions about db-optimization.

Which coding agents can use db-optimization?
db-optimization installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.