# database-optimizer

database-optimizer — a subagent for database performance analysis: finds bottlenecks in SQL queries, indexing, schema design and infrastructure.

- subagent · `type=agent` · Claude Code, Codex, Cursor · ★ 1357 repo stars
- Author: qdhenry
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/qdhenry/Claude-Command-Suite/tree/HEAD/.claude/agents/data-ai/database-optimizer.md
- Updated: 2026-03-01
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/agents/qdhenry-database-optimizer

## What it does

The subagent dissects slow queries with `EXPLAIN ANALYZE`, suggests indexes tailored to specific query patterns, and refines schemas through normalization or strategic denormalization. It spots N+1 queries, locking conflicts, and points out where to add caching layers like Redis.

Inside: file read/write, grep, bash, web search, and MCP servers `context7` (DBMS docs and optimization patterns) and `sequential-thinking` (step-by-step migration planning). Supports PostgreSQL, MySQL, MongoDB.

Before each recommendation it asks for the DBMS and table schemas. Never modifies data directly: outputs ready-to-run scripts for manual execution.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/agents/database-optimizer.md` — For all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention

### Codex

**Manually: put the files in place**
- File: `.codex/agents/database-optimizer.toml` — Codex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/

### Cursor

**Manually: put the files in place**
- File: `.cursor/agents/database-optimizer.md` — Cursor also reads .claude/agents/

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/qdhenry/Claude-Command-Suite/tree/HEAD/.claude/agents/data-ai/database-optimizer.md

## When to use it
- rewrite a slow SQL query after profiling it
- design indexes for frequent filter patterns
- detect N+1 queries in ORM code
- plan zero-downtime schema migrations
- add caching for expensive analytical queries

## Example prompts
- Profile the query in `queries/reports.sql` with `EXPLAIN ANALYZE` and show where it slows down
- Suggest indexes for the `orders` table to speed up filtering by status and date
- Find all places in the codebase where the ORM makes N+1 queries to `users`

## Similar
- [database-performance-optimizer](https://affpapa.org/en/nevibecode/agents/database-performance-optimizer.md) — subagent · ★ 1013 repo stars
- [database-performance-debugging](https://affpapa.org/en/nevibecode/skills/database-performance-debugging.md) — skill · 500 installs
- [database-cloud-optimization-database-optimizer](https://affpapa.org/en/nevibecode/agents/database-cloud-optimization-database-optimizer.md) — subagent · ★ 42780 repo stars
- [database](https://affpapa.org/en/nevibecode/mcp/database.md) — MCP server · ★ 10 repo stars
- [database-administrator](https://affpapa.org/en/nevibecode/agents/database-administrator.md) — subagent · 452 installs

## Other versions with the same name
- [database-optimizer · voltagent](https://affpapa.org/en/nevibecode/agents/database-optimizer.md) — 3320 installs
- [database-optimizer · voltagent](https://affpapa.org/en/nevibecode/agents/voltagent-database-optimizer.md) — ★ 6505 repo stars
- [database-optimizer · rohitg00](https://affpapa.org/en/nevibecode/agents/rohitg00-database-optimizer.md) — ★ 2858 repo stars

From the same set: [qdhenry/claude-command-suite](https://affpapa.org/en/nevibecode/by/qdhenry/claude-command-suite.md) — 112 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
