Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
jeffallan avatar

Database Optimizer

  • 4.2k installs
  • 10.8k repo stars
  • Updated May 20, 2026
  • jeffallan/claude-skills

Given a slow query or database performance issue, identify root cause (missing index, stale statistics, inefficient join plan, config misconfiguration), design a targeted optimization, and validate improvement with measu

About

Database Optimizer is a specialist skill for diagnosing and resolving database performance bottlenecks in PostgreSQL and MySQL. Developers invoke it when investigating slow queries, analyzing EXPLAIN ANALYZE output, designing covering indexes, or tuning configuration parameters like shared_buffers and work_mem. The core workflow captures baseline metrics, identifies inefficient query patterns and missing indexes, designs targeted optimizations (rewrites, partitioning, lock contention fixes), and validates improvements before production rollout. It enforces test-first discipline: always measure before and after each change, create indexes concurrently to avoid locks, and roll back if write performance or replication lag degrades. Output includes performance analysis, bottleneck root causes with EXPLAIN evidence, implementation SQL, and validation queries. Analyzes PostgreSQL and MySQL execution plans using EXPLAIN (ANALYZE, BUFFERS) to identify sequential scans, nested loops, and cache misses Designs covering indexes

  • Analyzes PostgreSQL and MySQL execution plans using EXPLAIN (ANALYZE, BUFFERS) to identify sequential scans, nested loop
  • Designs covering indexes and query rewrites with before/after cost comparison to reduce execution time without write amp
  • Provides database-specific tuning guidance for shared_buffers, work_mem, and other configuration parameters
  • Enforces safe incremental optimization: baseline capture, single-change validation, non-production testing, immediate ro
  • Generates monitoring recommendations and documents all decisions with metrics for auditability

Database Optimizer by the numbers

  • 4,245 all-time installs (skills.sh)
  • +135 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #154 of 4,386 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: HIGH risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

database-optimizer capabilities & compatibility

Capabilities
execute explain (analyze, buffers) and interpret · design b tree and covering indexes to eliminate · generate query rewrites to change join algorithm · recommend postgresql and mysql configuration par · identify missing statistics and lock contention · validate optimizations with before/after perform
Works with
postgres · mysql · datadog · splunk · grafana
Use cases
debugging · database · devops · testing
Platforms
macOS · Windows · Linux · WSL
Runs
Remote server
Pricing
Free
From the docs

What database-optimizer says it does

Invoke for index design, query rewrites, configuration tuning, partitioning strategies, lock contention resolution.
skill metadata, triggers
Always test changes in non-production first. Revert immediately if write performance degrades or replication lag increases.
Constraints section
npx skills add https://github.com/jeffallan/claude-skills --skill database-optimizer

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs4.2k
repo stars10.8k
Security audit3 / 3 scanners passed
Last updatedMay 20, 2026
Repositoryjeffallan/claude-skills

What it does

Analyze slow queries, design indexes, tune PostgreSQL and MySQL configuration to reduce execution time and improve cache efficiency.

Who is it for?

Backend engineers, database architects, and DevOps specialists optimizing PostgreSQL and MySQL systems in production or staging.

Skip if: NoSQL optimization, real-time query engines, data warehouse query tuning, schema redesign from scratch (focuses on existing schema optimization).

When should I use this skill?

Investigating slow queries, analyzing execution plans, designing index strategy, tuning configuration parameters, resolving lock contention, or improving cache efficiency.

What you get

Query execution time reduced by measured percent; indexes added without write amplification; configuration tuned for workload; monitoring in place to prevent regression.

  • Baseline performance metrics (query time, cost, buffer hit ratio)
  • EXPLAIN ANALYZE output with annotated bottleneck identification
  • Optimization strategy document with index, query rewrite, and config changes

By the numbers

  • Supports PostgreSQL 9.6+ and MySQL 5.7+ via EXPLAIN (ANALYZE, BUFFERS) / EXPLAIN FORMAT=JSON
  • Reference includes 5 optimization topics: query optimization, index strategies, PostgreSQL tuning, MySQL tuning, monitor
  • Core workflow enforces 5-step validation: baseline, bottleneck analysis, design, incremental implementation, result meas

Files

SKILL.mdMarkdownGitHub ↗

Database Optimizer

Senior database optimizer with expertise in performance tuning, query optimization, and scalability across multiple database systems.

When to Use This Skill

  • Analyzing slow queries and execution plans
  • Designing optimal index strategies
  • Tuning database configuration parameters
  • Optimizing schema design and partitioning
  • Reducing lock contention and deadlocks
  • Improving cache hit rates and memory usage

Core Workflow

1. Analyze Performance — Capture baseline metrics and run EXPLAIN ANALYZE before any changes 2. Identify Bottlenecks — Find inefficient queries, missing indexes, config issues 3. Design Solutions — Create index strategies, query rewrites, schema improvements 4. Implement Changes — Apply optimizations incrementally with monitoring; validate each change before proceeding to the next 5. Validate Results — Re-run EXPLAIN ANALYZE, compare costs, measure wall-clock improvement, document changes

⚠️ Always test changes in non-production first. Revert immediately if write performance degrades or replication lag increases.

Reference Guide

Load detailed guidance based on context:

TopicReferenceLoad When
Query Optimizationreferences/query-optimization.mdAnalyzing slow queries, execution plans
Index Strategiesreferences/index-strategies.mdDesigning indexes, covering indexes
PostgreSQL Tuningreferences/postgresql-tuning.mdPostgreSQL-specific optimizations
MySQL Tuningreferences/mysql-tuning.mdMySQL-specific optimizations
Monitoring & Analysisreferences/monitoring-analysis.mdPerformance metrics, diagnostics

Common Operations & Examples

Identify Top Slow Queries (PostgreSQL)

-- Requires pg_stat_statements extension
SELECT query,
       calls,
       round(total_exec_time::numeric, 2)  AS total_ms,
       round(mean_exec_time::numeric, 2)   AS mean_ms,
       round(stddev_exec_time::numeric, 2) AS stddev_ms,
       rows
FROM   pg_stat_statements
ORDER  BY mean_exec_time DESC
LIMIT  20;

Capture an Execution Plan

-- Use BUFFERS to expose cache hit vs. disk read ratio
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT o.id, c.name
FROM   orders o
JOIN   customers c ON c.id = o.customer_id
WHERE  o.status = 'pending'
  AND  o.created_at > now() - interval '7 days';

Reading EXPLAIN Output — Key Patterns to Find

PatternSymptomTypical Remedy
Seq Scan on large tableHigh row estimate, no filter selectivityAdd B-tree index on filter column
Nested Loop with large outer setExponential row growth in inner loopConsider Hash Join; index inner join key
cost=... rows=1 but actual rows=50000Stale statisticsRun ANALYZE <table>;
Buffers: hit=10 read=90000Low buffer cache hit rateIncrease shared_buffers; add covering index
Sort Method: external mergeSort spilling to diskIncrease work_mem for the session

Create a Covering Index

-- Covers the filter AND the projected columns, eliminating a heap fetch
CREATE INDEX CONCURRENTLY idx_orders_status_created_covering
    ON orders (status, created_at)
    INCLUDE (customer_id, total_amount);

Validate Improvement

-- Before optimization: save plan & timing
EXPLAIN (ANALYZE, BUFFERS) <query>;   -- note "Execution Time: X ms"

-- After optimization: compare
EXPLAIN (ANALYZE, BUFFERS) <query>;   -- target meaningful reduction in cost & time

-- Confirm index is actually used
SELECT indexname, idx_scan, idx_tup_read, idx_tup_fetch
FROM   pg_stat_user_indexes
WHERE  relname = 'orders';

MySQL: Find Slow Queries

-- Inspect slow query log candidates
SELECT * FROM performance_schema.events_statements_summary_by_digest
ORDER  BY SUM_TIMER_WAIT DESC
LIMIT  20;

-- Execution plan
EXPLAIN FORMAT=JSON
SELECT * FROM orders WHERE status = 'pending' AND created_at > NOW() - INTERVAL 7 DAY;

Constraints

MUST DO

  • Capture EXPLAIN (ANALYZE, BUFFERS) output before optimizing — this is the baseline
  • Measure performance before and after every change
  • Create indexes with CONCURRENTLY (PostgreSQL) to avoid table locks
  • Test in non-production; roll back if write performance or replication lag worsens
  • Document all optimization decisions with before/after metrics
  • Run ANALYZE after bulk data changes to refresh statistics

MUST NOT DO

  • Apply optimizations without a measured baseline
  • Create redundant or unused indexes
  • Make multiple changes simultaneously (impossible to attribute impact)
  • Ignore write amplification caused by new indexes
  • Neglect VACUUM / statistics maintenance

Output Templates

When optimizing database performance, provide: 1. Performance analysis with baseline metrics (query time, cost, buffer hit ratio) 2. Identified bottlenecks and root causes (with EXPLAIN evidence) 3. Optimization strategy with specific changes 4. Implementation SQL / config changes 5. Validation queries to measure improvement 6. Monitoring recommendations

Documentation

Related skills

How it compares

Unlike generic backend or DevOps skills, Database Optimizer focuses narrowly on performance diagnosis and optimization for existing schemas, not schema redesign, data warehouse tuning, or NoSQL systems. Complements devop

FAQ

Should I create multiple indexes or one covering index?

Covering indexes reduce heap fetches and improve cache locality but increase write cost. Create one covering index per major query pattern; avoid redundant indexes. Always measure index scan count (pg_stat_user_indexes) to validate reuse.

Why is my EXPLAIN plan estimate so different from actual rows?

Stale table statistics. Run ANALYZE <table> to refresh statistics, especially after bulk data loads. If estimates remain wrong, consider ANALYZE on columns with non-uniform distribution.

Can I optimize without downtime?

Yes: use CREATE INDEX CONCURRENTLY in PostgreSQL (non-blocking), test in staging first, and deploy changes incrementally. Always roll back immediately if write performance or replication lag worsens.

Is Database Optimizer safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Backend & APIsdatabasespipelines

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.