db-optimization skill
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.
- GitHub stars
- 8
- Files
- 1
- Last commit
- Sep 24, 2026
- License
- MIT
- Allowed tools
- —
What does the db-optimization skill do?
db-optimization uses 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.
How to install the db-optimization skill
Each command copies the skill folder into the client's skills directory. Restart the client or start a new session to load it.Install the db-optimization skill in Plugin
/plugin marketplace add jdanigo/hydraia /plugin install hydraia@hydraia
Install the db-optimization skill in Claude Code
~/.claude/skills/db-optimization/SKILL.md
$ npx degit jdanigo/hydraia/skills/db-optimization ~/.claude/skills/db-optimizationInstall the db-optimization skill in Claude Code (project)
.claude/skills/db-optimization/SKILL.md
$ npx degit jdanigo/hydraia/skills/db-optimization .claude/skills/db-optimizationInstall the db-optimization skill in Codex
~/.agents/skills/db-optimization/SKILL.md
$ npx degit jdanigo/hydraia/skills/db-optimization ~/.agents/skills/db-optimizationInstall the db-optimization skill in Gemini CLI
~/.gemini/skills/db-optimization/SKILL.md
$ npx degit jdanigo/hydraia/skills/db-optimization ~/.gemini/skills/db-optimizationInstall the db-optimization skill in Claude.ai
npx degit jdanigo/hydraia/skills/db-optimization db-optimization && zip -r db-optimization.zip db-optimization # claude.ai → Customize → Skills → + → Create skill → Upload a skill → db-optimization.zip
SKILL.md
View on GitHubDB 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.
Expand-contract migration protocol
- Expand: add the new column/table/index alongside the old — additive, backward-compatible, online.
- Dual-write + backfill: application writes both shapes; backfill history in batches (bounded, throttled, resumable).
- Switch reads to the new shape behind a verified flag; watch metrics.
- 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 (INlists), 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.
Files in this skill
1db-optimization skill questions
How do I install the db-optimization skill in Claude Code?
Run npx degit jdanigo/hydraia/skills/db-optimization ~/.claude/skills/db-optimization. Claude Code loads skills from ~/.claude/skills (all projects) or .claude/skills (one project) and uses a skill when its description matches the task.
Which clients can use the db-optimization skill?
Any client that reads the Agent Skills format: Claude Code, Codex, Gemini CLI and claude.ai (upload as a ZIP). Scripts in the skill run only where the client allows code execution.