Agent skill

Database Optimization

by rohitg00 in rohitg00/awesome-claude-code-toolkit

Query optimization, indexing strategies, and database performance tuning for PostgreSQL and MySQL

Apache-2.0Auto-check passedDatabases

Install Database Optimization

skills CLI
$ npx skills add rohitg00/awesome-claude-code-toolkit --skill database-optimization -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install rohitg00/awesome-claude-code-toolkit database-optimization --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/rohitg00/awesome-claude-code-toolkit.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/database-optimization .claude/skills/database-optimization && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
database-optimization
GitHub stars
2.7k
Token cost
~1.3k tokens
SKILL.md length
370 words
Files
1
Skills in repo
37
Repo updated
First seen
Licence
Apache-2.0

At a glance

Query optimization, indexing strategies, and database performance tuning for PostgreSQL and MySQL

  • Works in 10 steps: Run EXPLAIN ANALYZE and read the plan → Check for sequential scans on tables… → Verify index usage (check idx_scan in… → …
  • Tasks that involve Query optimization
  • SKILL.md covers EXPLAIN Analysis, Index Strategies, N+1 Query Detection and Connection Pooling, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Database Optimization is an agent skill from rohitg00/awesome-claude-code-toolkit. Query optimization, indexing strategies, and database performance tuning for PostgreSQL and MySQL

Its SKILL.md is about 1.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering Query optimization. It works with PostgreSQL and MySQL. The repository describes itself as: The most comprehensive toolkit for Claude Code -- 135 agents, 35 curated skills, 42 commands, 176+ plugins, 20 hooks, 15 rules, 7 templates, 14 MCP configs, 26 companion apps, 52… The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Query optimization

Example prompts

  • “/database-optimization”

Requirements

  • Python 3

Workflow steps

10 steps, taken from the first numbered list in SKILL.md.

  1. Run EXPLAIN ANALYZE and read the plan
  2. Check for sequential scans on tables with >10K rows
  3. Verify index usage (check idx_scan in pg_stat_user_indexes)
  4. Look for implicit type casts that prevent index use
  5. Replace SELECT * with specific columns
  6. Add LIMIT to queries that only need a subset
  7. Use EXISTS instead of COUNT(*) > 0
  8. Batch INSERT/UPDATE operations (500-1000 rows per batch)
  9. Avoid functions on indexed columns in WHERE clauses
  10. Monitor slow query log (pg: log_min_duration_statement = 100)

What it can do on your machine

Read from SKILL.md and the folder at commit ebdf1d5. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are sql, python and javascript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Database Optimization loads about 1.3k tokens when it runs. Until then it costs about 30 tokens; SKILL.md has 370 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~30
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from rohitg00/awesome-claude-code-toolkit at commit ebdf1d5, republished under its Apache-2.0 licence (© rohitg00). 370 words, ~1,332 tokens.

Download SKILL.mdSave it as .claude/skills/database-optimization/SKILL.md (or your agent's skills folder).
name
database-optimization
description
Query optimization, indexing strategies, and database performance tuning for PostgreSQL and MySQL

Database Optimization

EXPLAIN Analysis

Always run EXPLAIN ANALYZE before optimizing. Read the output bottom-up.

sql
-- PostgreSQL
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT) SELECT ...;

-- MySQL
EXPLAIN ANALYZE SELECT ...;

Key metrics to watch:

  • Seq Scan on large tables = missing index
  • Nested Loop with high row count = consider hash/merge join
  • Sort without index = add index on sort column
  • Rows estimated vs actual divergence = stale statistics, run ANALYZE

Index Strategies

B-tree (default, most cases)
sql
CREATE INDEX idx_users_email ON users (email);
CREATE INDEX idx_orders_user_date ON orders (user_id, created_at DESC);

Use for: equality, range queries, sorting. Column order matters in composite indexes: put equality columns first, then range/sort columns.

Partial Index (PostgreSQL)
sql
CREATE INDEX idx_orders_pending ON orders (created_at)
  WHERE status = 'pending';

Use when queries always filter on a specific condition. Dramatically smaller than full indexes.

GIN (PostgreSQL - arrays, JSONB, full-text)
sql
CREATE INDEX idx_products_tags ON products USING GIN (tags);
CREATE INDEX idx_docs_search ON documents USING GIN (to_tsvector('english', content));
GiST (PostgreSQL - spatial, range types)
sql
CREATE INDEX idx_locations_point ON locations USING GiST (coordinates);
CREATE INDEX idx_events_period ON events USING GiST (tsrange(start_at, end_at));
Covering Index (index-only scans)
sql
-- PostgreSQL
CREATE INDEX idx_users_email_name ON users (email) INCLUDE (name);

-- MySQL
CREATE INDEX idx_users_email_name ON users (email, name);

N+1 Query Detection

Symptom: 1 query to fetch parent + N queries for each child.

python
# BAD: N+1
users = db.query(User).all()
for user in users:
    print(user.orders)  # triggers query per user

# GOOD: eager load
users = db.query(User).options(joinedload(User.orders)).all()
javascript
// BAD: N+1
const users = await User.findAll();
for (const user of users) {
  const orders = await Order.findAll({ where: { userId: user.id } });
}

// GOOD: batch load
const users = await User.findAll({ include: [Order] });

Detection: enable query logging, count queries per request. More than 10 queries for a single endpoint is a red flag.

Connection Pooling

Rule of thumb: pool_size = (core_count * 2) + disk_count
Typical web app: 10-20 connections per app instance

PostgreSQL:

  • Use PgBouncer in transaction mode for serverless/high-connection scenarios
  • Set idle_in_transaction_session_timeout = '30s'
  • Monitor with pg_stat_activity

MySQL:

  • Set max_connections based on available RAM (each connection uses ~10MB)
  • Use ProxySQL for connection multiplexing
  • Monitor with SHOW PROCESSLIST

Read Replicas

  • Route all SELECT queries to replicas
  • Route all writes to primary
  • Account for replication lag (typically 10-100ms)
  • Never read-after-write from a replica; use primary for consistency-critical reads
  • Use connection-level routing, not query-level
python
# SQLAlchemy read replica routing
class RoutingSession(Session):
    def get_bind(self, mapper=None, clause=None):
        if self._flushing or self.is_modified():
            return engines["primary"]
        return engines["replica"]

Partition Strategies

Range Partitioning (time-series data)
sql
-- PostgreSQL
CREATE TABLE events (
    id bigint GENERATED ALWAYS AS IDENTITY,
    created_at timestamptz NOT NULL,
    data jsonb
) PARTITION BY RANGE (created_at);

CREATE TABLE events_2025_q1 PARTITION OF events
    FOR VALUES FROM ('2025-01-01') TO ('2025-04-01');
CREATE TABLE events_2025_q2 PARTITION OF events
    FOR VALUES FROM ('2025-04-01') TO ('2025-07-01');
Show full SKILL.md (152 more words)Show less
Hash Partitioning (even distribution)
sql
CREATE TABLE sessions (
    id uuid PRIMARY KEY,
    user_id bigint NOT NULL
) PARTITION BY HASH (user_id);

CREATE TABLE sessions_0 PARTITION OF sessions FOR VALUES WITH (MODULUS 4, REMAINDER 0);
CREATE TABLE sessions_1 PARTITION OF sessions FOR VALUES WITH (MODULUS 4, REMAINDER 1);

Partition when tables exceed 50-100GB or when you need to drop old data quickly.

Query Optimization Checklist

  1. Run EXPLAIN ANALYZE and read the plan
  2. Check for sequential scans on tables with >10K rows
  3. Verify index usage (check idx_scan in pg_stat_user_indexes)
  4. Look for implicit type casts that prevent index use
  5. Replace SELECT * with specific columns
  6. Add LIMIT to queries that only need a subset
  7. Use EXISTS instead of COUNT(*) > 0
  8. Batch INSERT/UPDATE operations (500-1000 rows per batch)
  9. Avoid functions on indexed columns in WHERE clauses
  10. Monitor slow query log (pg: log_min_duration_statement = 100)

Dangerous Patterns

  • LIKE '%term%' on unindexed columns (use full-text search instead)
  • ORDER BY RANDOM() (use TABLESAMPLE or application-level randomization)
  • SELECT DISTINCT masking a join problem
  • Missing WHERE on UPDATE/DELETE (always verify with SELECT first)
  • Long-running transactions holding locks
  • Using OFFSET for deep pagination (use keyset/cursor pagination instead)

© rohitg00, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/database-optimization of rohitg00/awesome-claude-code-toolkit.

Open the folder on GitHubat commit ebdf1d5

Compare with similar skills

Database Optimization next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Database Optimization compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Database Optimization this skillrohitg00/awesome-claude-code-toolkit2.7k—~1.3kAutomated safety check: PassApache-2.0
DB Ops SopOpenDCAI/DataMind406—~388Automated safety check: PassApache-2.0
Altimate Data Warehouse DelegateAltimateAI/data-engineering-skills127—~1.4kAutomated safety check: PassMIT
Database OptimizerJeffallan/claude-skills12k—~1.6kAutomated safety check: PassMIT
SQL ProJeffallan/claude-skills12k—~1.3kAutomated safety check: PassMIT
Database OptimizerAratKruglik/claude-laravel155—~1kAutomated safety check: PassNone

Similar skills

  • DB Ops Sop

    OpenDCAI/DataMind

    Database operations runbook — backup, recovery, performance tuning, troubleshooting.

    406 GitHub stars~388 tokensUpdated 17 days ago
    DatabasesAuto-check passed
  • Altimate Data Warehouse Delegate

    AltimateAI/data-engineering-skills

    Delegates dbt and warehouse tasks such as lineage, migrations and cost attribution to the altimate-code CLI agent and relays its answer back.

    127 GitHub stars~1.4k tokensUpdated 6 days ago
    DatabasesAuto-check passed
  • Database Optimizer

    Jeffallan/claude-skills

    Tunes PostgreSQL and MySQL performance by analyzing slow queries and execution plans, designing indexes, rewriting queries and adjusting configuration, one validated change at a time.

    12k GitHub stars~1.6k tokensUpdated 4 days ago
    DatabasesAuto-check passed
  • SQL Pro

    Jeffallan/claude-skills

    Optimizes SQL queries and designs schemas using CTEs, window functions, covering indexes and EXPLAIN ANALYZE, with notes on dialect differences between major databases.

    12k GitHub stars~1.3k tokensUpdated 4 days ago
    DatabasesAuto-check passed
  • Database Optimizer

    AratKruglik/claude-laravel

    A skill your agent uses when investigating slow queries, analyzing execution plans, or optimizing database performance.

    155 GitHub stars~1k tokensUpdated 5 mo ago
    DatabasesAuto-check passed
  • Database Optimizer

    zebbern/claude-code-guide

    A skill your agent uses when investigating slow queries, analyzing execution plans, or optimizing database performance.

    4.6k GitHub stars~967 tokensUpdated today
    DatabasesAuto-check passed

More from rohitg00/awesome-claude-code-toolkit

All 37 skills in this repo
  • Accessibility Wcag

    rohitg00/awesome-claude-code-toolkit

    Web accessibility patterns for WCAG 2.2 compliance including ARIA, keyboard navigation, screen readers, and testing

    2.7k GitHub stars~1.4k tokensUpdated 4 mo ago
    Auto-check passed
  • API Design Patterns

    rohitg00/awesome-claude-code-toolkit

    REST API design with resource naming, pagination, versioning, and OpenAPI spec generation

    2.7k GitHub stars~1.2k tokensUpdated 4 mo ago
    Auto-check passed
  • Authentication Patterns

    rohitg00/awesome-claude-code-toolkit

    Authentication and authorization patterns including OAuth2, JWT, RBAC, session management, and PKCE flows

    2.7k GitHub stars~1.4k tokensUpdated 4 mo ago
    Auto-check passed
  • AWS Cloud Patterns

    rohitg00/awesome-claude-code-toolkit

    AWS cloud patterns for Lambda, ECS, S3, DynamoDB, and Infrastructure as Code with CDK/Terraform

    2.7k GitHub stars~1.1k tokensUpdated 4 mo ago
    Auto-check passed
  • CI CD Pipelines

    rohitg00/awesome-claude-code-toolkit

    CI/CD pipeline patterns for GitHub Actions, GitLab CI, testing strategies, and deployment automation

    2.7k GitHub stars~1.1k tokensUpdated 4 mo ago
    Auto-check passed
  • Continuous Learning

    rohitg00/awesome-claude-code-toolkit

    Auto-extract patterns from coding sessions, track corrections, and build reusable knowledge with confidence scoring

    2.7k GitHub stars~1.4k tokensUpdated 4 mo ago
    Auto-check passed

Works with

Categories

Questions about Database Optimization

What does Database Optimization do?

Query optimization, indexing strategies, and database performance tuning for PostgreSQL and MySQL. Database Optimization is an agent skill from rohitg00/awesome-claude-code-toolkit.

When should I use Database Optimization?

Database Optimization fits situations like: tasks that involve Query optimization.

How do I install Database Optimization in Claude Code?

Run `npx skills add rohitg00/awesome-claude-code-toolkit --skill database-optimization -a claude-code`. Or copy the skill folder (skills/database-optimization in rohitg00/awesome-claude-code-toolkit) into .claude/skills/database-optimization in your project. Claude Code loads it when a task matches its description.

How do I install Database Optimization in Codex?

Run `npx skills add rohitg00/awesome-claude-code-toolkit --skill database-optimization -a codex`. Or copy the skill folder (skills/database-optimization in rohitg00/awesome-claude-code-toolkit) into .agents/skills/database-optimization in your project. Codex loads it when a task matches its description.

Can I use Database Optimization in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add rohitg00/awesome-claude-code-toolkit --skill database-optimization -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/database-optimization, .gemini/skills/database-optimization, .github/skills/database-optimization and .opencode/skills/database-optimization in your project.

What does Database Optimization need to run?

SKILL.md names no scripts, command-line tools or credentials: Database Optimization is instructions for the agent only. Our summary lists: Python 3.

Does Database Optimization access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Database Optimization safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Database Optimization use?

Database Optimization is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Database Optimization use?

About 1.3k tokens (SKILL.md is roughly 5.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Database Optimization?

Skills that share tags, products or a category with Database Optimization: DB Ops Sop (OpenDCAI/DataMind, 406 stars), Altimate Data Warehouse Delegate (AltimateAI/data-engineering-skills, 127 stars), Database Optimizer (Jeffallan/claude-skills, 12k stars) and SQL Pro (Jeffallan/claude-skills, 12k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Database Optimization?

rohitg00 (a GitHub user) maintains it in rohitg00/awesome-claude-code-toolkit, which has 2,683 GitHub stars. The repository holds 37 skills in this directory. The repository was last updated on May 12, 2026.

Source: rohitg00/awesome-claude-code-toolkit on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.