/devops-infrastructure:analyze-db-performance <db-connection-string-or-log-file>from devops-infrastructure
Analyzes PostgreSQL performance by examining slow queries, table sizes, and index usage via pg_stat_statements and system metrics.
Ships in devops-infrastructure. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Analyze PostgreSQL database performance using pg_stat_statements, slow query logs, and system metrics.
Validate Input: Check if argument is:
Gather Performance Data: Launch 3 parallel Haiku agents to collect database metrics concurrently:
Agent #1: Slow Query Analyzer
SELECT query, calls, total_exec_time, mean_exec_time, max_exec_time
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 20;
Agent #2: Table Size Analyzer
SELECT schemaname, tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename))
FROM pg_tables
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
Agent #3: Index Usage Analyzer
SELECT schemaname, tablename, indexname, idx_scan
FROM pg_stat_user_indexes
WHERE idx_scan = 0
ORDER BY pg_relation_size(indexrelid) DESC;
Launch 2 parallel Sonnet agents to analyze performance data:
Agent #4: PostgreSQL Specialist (postgresql-specialist agent)
Agent #5: General Database Specialist (database-specialist agent)
Aggregate Analysis: Merge findings from both specialists, prioritizing PostgreSQL-specific recommendations.
# Step 1: Validate input (sequential)
connection_string = validate_input($argument)
# Step 2: Launch 3 parallel Haiku agents for data collection.
# The Task tool only accepts `subagent_type`, `prompt`, and `description`.
# Each agent runs the read-only psql SELECT itself by following the prompt;
# the SQL is embedded in the prompt rather than passed as Task parameters.
if connection_string:
Task(subagent_type: "general-purpose", description: "Collect slow queries", prompt: "Run this read-only command and return the raw output:\npsql ${connection_string} -c \"SELECT query, calls, total_exec_time, mean_exec_time, max_exec_time FROM pg_stat_statements ORDER BY mean_exec_time DESC LIMIT 20;\"")
Task(subagent_type: "general-purpose", description: "Collect table sizes", prompt: "Run this read-only command and return the raw output:\npsql ${connection_string} -c \"SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) FROM pg_tables ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;\"")
Task(subagent_type: "general-purpose", description: "Collect index usage", prompt: "Run this read-only command and return the raw output:\npsql ${connection_string} -c \"SELECT schemaname, tablename, indexname, idx_scan FROM pg_stat_user_indexes WHERE idx_scan = 0 ORDER BY pg_relation_size(indexrelid) DESC;\"")
# Wait for all 3 data collection agents to complete
slow_queries = get_task_result(agent1)
table_sizes = get_task_result(agent2)
index_usage = get_task_result(agent3)
# Step 3: Launch 2 parallel Sonnet agents for analysis
Task(subagent_type: "postgresql-specialist", model: "sonnet", prompt: "Analyze PostgreSQL performance data: Slow queries: ${slow_queries}, Table sizes: ${table_sizes}, Index usage: ${index_usage}. Generate optimization recommendations.")
Task(subagent_type: "database-specialist", model: "sonnet", prompt: "Analyze database performance patterns: Slow queries: ${slow_queries}, Table sizes: ${table_sizes}, Index usage: ${index_usage}. Identify anti-patterns and suggest improvements.")
# Step 4: Aggregate analysis from both specialists
# Step 5: Generate unified report (next section)
Note: Data collection agents (Haiku) run concurrently since SQL queries are independent. Analysis agents (Sonnet) run concurrently after data collection completes.
Generate Report:
Provide Actionable Recommendations:
# PostgreSQL Performance Analysis
## Summary
- **Database**: my_app_production
- **Analysis Date**: 2025-12-03
- **Total Queries Analyzed**: 1,234
- **Slow Queries (>1s)**: 15
## Critical Issues 🔴
### 1. Missing Index on users.email
**Query**: `SELECT * FROM users WHERE email = $1`
**Calls**: 10,234 | **Avg Time**: 2,450ms | **Impact**: HIGH
**Recommendation**:
```sql
CREATE INDEX CONCURRENTLY idx_users_email ON users(email);
Expected Improvement: 95% reduction in query time
Size: 245 MB | Scans: 0
Recommendation:
DROP INDEX CONCURRENTLY idx_posts_legacy;
Storage Saved: 245 MB
# Current vs Recommended
shared_buffers = 128MB → 2GB # 25% of RAM
effective_cache_size = 4GB → 12GB # 75% of RAM
work_mem = 4MB → 16MB # For sorting/hashing
-- Add to monitoring system (run every 5 minutes)
SELECT COUNT(*) as slow_queries
FROM pg_stat_statements
WHERE mean_exec_time > 1000;
## Examples
```bash
# Analyze using connection string
/analyze-db-performance postgres://user:pass@localhost:5432/mydb
# Analyze slow query log file
/analyze-db-performance /var/log/postgresql/slow-queries.log
# Auto-detect local PostgreSQL
/analyze-db-performance
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub sgaunet/claude-plugins --plugin devops-infrastructureOther plugins' skills for the same job