# database-optimizer

A Claude skill that digs into database bottlenecks: execution plans, indexes, N+1, caching and partitioning. Useful when queries are slow and the reason isn't obvious.

- skill · `type=skill` · Claude Code · 286 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/skills/database/database-optimizer
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/skills/database-optimizer

## What it does

Install the skill and Claude starts acting as a database consultant. It covers execution plan analysis with `EXPLAIN ANALYZE`, query rewriting around subqueries and JOINs, window functions and recursive CTEs. Indexing gets its own section: B-tree, Hash, GiST, GIN, BRIN, composite and partial indexes, plus index bloat and rebuild strategies.

N+1 detection is handled too. The skill walks through ORM query analysis for Django ORM, SQLAlchemy, Entity Framework and ActiveRecord, then the fixes — eager loading, batch queries, DataLoader for GraphQL. Caching spans application-level results, Redis and Memcached, down to the database buffer pool, with TTL and event-driven invalidation. Scaling is covered by partitioning, sharding, read replicas and async writes.

PostgreSQL, MySQL, SQL Server, Oracle, MongoDB, DynamoDB and cloud databases like RDS, Aurora, Azure SQL and Cloud SQL are all in scope. For worked examples the skill points to `resources/implementation-playbook.md`, so that file needs to sit in the skill directory — without it you're left with the general instructions. Name your engine up front, because index advice for PostgreSQL and SQL Server pulls in different directions.

## Requirements
- Works with: PostgreSQL

## Install

### Claude Code (native platform)

1. **claude-code-templates**
```bash
npx claude-code-templates@latest --skill database/database-optimizer
```

2. **Skills CLI (Vercel)**
```bash
npx skills add davila7/claude-code-templates --skill database-optimizer -a claude-code
```

3. **Manually: put the files in place**
- File: `~/.claude/skills/database-optimizer/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/database-optimizer/

### Codex

**Manually: put the files in place**
- File: `.agents/skills/database-optimizer/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

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

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install davila7/claude-code-templates database-optimizer
```

2. **Manually: put the files in place**
- File: `.github/skills/database-optimizer/SKILL.md`

### Gemini CLI

**Platform CLI**
```bash
gemini skills install https://github.com/davila7/claude-code-templates --path cli-tool/components/skills/database/database-optimizer
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/database-optimizer/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

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/skills/database/database-optimizer

## When to use it
- read an execution plan for a slow query
- find and fix N+1 queries in ORM code
- pick indexes for frequently filtered columns
- plan partitioning for a large table
- add a cache layer between app and database

## Example prompts
- Look at the execution plan for this query and tell me what to rewrite
- This Django ORM code has an N+1 problem — find it and fix it
- Which indexes should I add to the orders table for date and status filters?

## Similar
- [sql-pro](https://affpapa.org/en/nevibecode/skills/httpsgithubcomjeffallan-sql-pro.md) — skill · 6400 installs
- [database-design](https://affpapa.org/en/nevibecode/skills/moizibnyousaf-database-design.md) — skill · 604 installs
- [database-indexing-strategy](https://affpapa.org/en/nevibecode/skills/database-indexing-strategy.md) — skill · 486 installs
- [sql-query-optimization](https://affpapa.org/en/nevibecode/skills/sql-query-optimization.md) — skill · 520 installs
- [database-cloud-optimization-database-optimizer](https://affpapa.org/en/nevibecode/agents/database-cloud-optimization-database-optimizer.md) — subagent · ★ 41729
- [postgresql-best-practices](https://affpapa.org/en/nevibecode/skills/postgresql-best-practices.md) — skill · 1500 installs

## Other versions with the same name
- [database-optimizer · jeffallan](https://affpapa.org/en/nevibecode/skills/httpsgithubcomjeffallan-database-optimizer.md) — 6000 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
