# database-optimization

A subagent for slow queries: reads execution plans, suggests indexes and connection pool settings.

- subagent · `type=agent` · Claude Code · 3924 installs
- Author: davila7
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/agents/database/database-optimization.md
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/agents/database-optimization

## What it does

The `database-optimization` subagent handles database performance work: execution plan analysis, indexing, connection pooling, transactions, schema design. It runs with `Read`, `Write`, `Edit` and `Bash`, so it can fire off `EXPLAIN ANALYZE` itself and edit your SQL files.

The workflow is measure first, optimize second. It won't guess from source code alone — it asks for real numbers and builds indexes from actual query patterns. You get rewritten queries with plan comparisons, index recommendations with impact estimates, connection pool configs, and monitoring queries. PostgreSQL and MySQL get engine-specific treatment.

Worth reaching for when a query suddenly crawls and the cause isn't obvious. Without access to a live database or at least its statistics, though, there's little to work with: the subagent needs real execution plans, not guesses. Behind a proxy or private mirror, set that up in your environment or the tool's config file rather than on the install line.

## Requirements
- Works with: PostgreSQL

## Install

### Claude Code (native platform)

1. **claude-code-templates**
```bash
npx claude-code-templates@latest --agent database/database-optimization
```

2. **Manually: put the files in place**
- File: `.claude/agents/database-optimization.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-optimization.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-optimization.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/davila7/claude-code-templates/tree/HEAD/cli-tool/components/agents/database/database-optimization.md

## When to use it
- trace a slow query back through its execution plan
- pick indexes that match real query patterns
- compare plans before and after rewriting SQL
- size a connection pool for the workload
- review schema design and plan migrations

## Example prompts
- Dig into this slow query: pull the execution plan and tell me what to rewrite
- Check the indexes on the orders table and tell me which ones are missing
- Compare the execution plan before and after my query change

## Similar
- [database-optimizer](https://affpapa.org/en/nevibecode/agents/database-optimizer.md) — subagent · 3320 installs
- [ai-engineer](https://affpapa.org/en/nevibecode/agents/ai-engineer.md) — subagent · 7687 installs
- [business-analyst](https://affpapa.org/en/nevibecode/agents/business-analyst.md) — subagent · 3855 installs
- [sql-pro](https://affpapa.org/en/nevibecode/agents/voltagent-community-sql-pro.md) — subagent · 3602 installs
- [sql-pro](https://affpapa.org/en/nevibecode/agents/sql-pro.md) — subagent · 3602 installs
- [data-scientist](https://affpapa.org/en/nevibecode/agents/voltagent-community-data-scientist.md) — subagent · 3342 installs

From the same set: [davila7/claude-code-templates](https://affpapa.org/en/nevibecode/by/davila7/claude-code-templates.md) — 205 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
