Skip to main content
command

optimize-database-performance — Claude Code command for database

A Claude slash command that walks through slow queries, indexes and schema, then tells you what to rewrite. Useful when a page stalls on one SELECT.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --command performance/optimize-database-performance
Open on GitHub

What optimize-database-performance does

The command runs a ten-step pass over your database: it pulls execution plans for slow queries, checks which indexes actually get used, looks at schema design and data types, then reviews connection pooling and result caching. Read replicas, table maintenance and load testing come after that. It targets PostgreSQL, MySQL and MongoDB, and you pick the engine with a flag.

There are no scripts inside, just instructions for the agent. The command is allowed to use Read, Bash, Grep and Glob, so it reads project files and runs shell commands. Invoke it as /optimize-database-performance --postgresql, or pass the database name as the argument.

One constraint is baked into the command itself: it insists you measure performance before and after every change. Without access to a running database and its logs, the sections on connection pooling, replicas and vacuum stay theoretical. If your setup blocks diagnostic shell commands, a good chunk of the analysis never runs.

What it helps with

  • find slow queries in the logs and rewrite them
  • drop unused and duplicate indexes
  • split a large table into partitions
  • tune connection pool size and timeouts
  • compare execution plans before and after a change

Example prompts for the agent

  • /optimize-database-performance --postgresql
  • /optimize-database-performance --mysql
  • /optimize-database-performance mongodb

How to install optimize-database-performance

1claude-code-templates

npx claude-code-templates@latest --command performance/optimize-database-performance

2Manually: put the files in place

.claude/commands/optimize-database-performance.md

Call it with /optimize-database-performance. For all projects use ~/.claude/commands/

Questions about optimize-database-performance

How do I install optimize-database-performance in Claude?

Run npx claude-code-templates@latest --command performance/optimize-database-performance. The command lands in .claude/commands/optimize-database-performance.md.

What does optimize-database-performance do?

It reviews queries, indexes, schema, connection pooling and caching, then suggests concrete changes for your workload. It also covers read replicas, table maintenance and benchmarking.

Which databases does it support?

PostgreSQL, MySQL and MongoDB. Set the engine with --postgresql, --mysql or --mongodb, or just pass the database name as the argument.

Source text

optimize-database-performance.md · MIT
---
allowed-tools: Read, Bash, Grep, Glob
argument-hint: "[database-type] | --postgresql | --mysql | --mongodb"
description: Optimize database queries, indexing, and performance for improved response times and scalability
---

# Optimize Database Performance

Optimize database queries and performance: **$ARGUMENTS**

## Instructions

1. **Database Performance Analysis**
   - Analyze current database performance and identify bottlenecks
   - Review slow query logs and execution plans
   - Assess database schema design and normalization
   - Evaluate indexing strategy and query patterns
   - Monitor database resource utilization (CPU, memory, I/O)

2. **Query Optimization**
   - Identify and optimize slow-performing queries
   - Analyze query execution plans and optimization strategies
   - Rewrite queries for better performance and efficiency
   - Implement query hints and optimization directives
   - Configure query timeout and resource limits

3. **Index Strategy Optimization**
   - Analyze existing indexes and their usage patterns
   - Design optimal indexing strategy for query patterns
   - Create composite indexes for multi-column queries
   - Implement covering indexes to avoid table lookups
   - Remove unused and redundant indexes

4. **Schema Design Optimization**
   - Optimize table structure and data types
   - Implement denormalization strategies for read-heavy workloads
   - Design partitioning strategies for large tables
   - Create materialized views for complex aggregations
   - Optimize foreign key relationships and constraints

5. **Connection Pool Optimization**
   - Configure optimal database connection pooling settings
   - Tune connection pool size and timeout settings
   - Implement connection monitoring and health checks
   - Optimize connection lifecycle and cleanup procedures
   - Configure connection security and SSL settings

6. **Query Result Caching**
   - Implement intelligent database result caching
   - Design cache invalidation strategies for data consistency
   - Set up query-level and result-set caching
   - Configure cache expiration and refresh policies
   - Monitor cache effectiveness and hit rates

7. **Database Monitoring and Profiling**
   - Set up comprehensive database performance monitoring
   - Monitor query performance and resource usage
   - Track database connections and session activity
   - Implement alerting for performance degradation
   - Configure automated performance reporting

8. **Read Replica and Load Balancing**
   - Configure read replicas for query distribution
   - Implement intelligent read/write query routing
   - Set up load balancing across database instances
   - Monitor replication lag and consistency
   - Configure failover and disaster recovery procedures

9. **Database Vacuum and Maintenance**
   - Implement automated database maintenance procedures
   - Configure vacuum and analyze operations for optimal performance
   - Set up index rebuilding and maintenance schedules
   - Monitor table bloat and fragmentation
   - Implement automated cleanup and archival strategies

10. **Performance Testing and Benchmarking**
    - Set up database performance testing frameworks
    - Implement load testing scenarios for realistic workloads
    - Benchmark query performance under different conditions
    - Test database scalability and capacity limits
    - Monitor performance regression and improvements

Focus on database optimizations that provide the most significant performance improvements for your specific workload patterns. Always measure performance before and after changes to validate optimizations.

© davila7 · MIT · davila7/claude-code-templates

Similar slash commands

All slash commands for Data and databases →

From the same set205

The whole set →

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor