Comprehensive PostgreSQL configuration and usage analysis for Rails applications. Use when Claude Code needs to analyze a Rails codebase for database performance issues, optimization opportunities, or best practice violations. Detects N+1 queries, missing indexes, suboptimal database configurations, anti-patterns, and provides actionable recommendations. Ideal for performance audits, optimization tasks, or when users ask to "analyze the database", "check for N+1 queries", "optimize PostgreSQL", "review database performance", or "suggest database improvements".
Analyzes Rails apps for PostgreSQL performance issues like N+1 queries, missing indexes, and configuration problems. Use when users ask to "analyze database performance" or "check for N+1 queries" to provide actionable optimization recommendations.
/plugin marketplace add el-feo/ai-context/plugin install ruby-rails@jebs-dev-toolsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/anti_patterns.mdreferences/performance_guide.mdscripts/analyze_config.pyscripts/analyze_indexes.pyscripts/analyze_n_plus_one.pyAnalyze Rails applications for PostgreSQL performance issues and provide actionable optimization recommendations based on "High Performance PostgreSQL for Rails" best practices.
This skill performs comprehensive analysis of Rails applications to identify:
Run these scripts from the Rails application root directory to analyze different aspects of the codebase:
python3 scripts/analyze_n_plus_one.py
Detects potential N+1 query issues by analyzing:
includes, preload, or eager_load callspython3 scripts/analyze_indexes.py
Identifies indexing opportunities:
python3 scripts/analyze_config.py
Reviews database.yml for:
When a user requests PostgreSQL analysis, follow this workflow:
Clarify what the user wants to analyze:
Based on the request, run one or more analysis scripts:
# For comprehensive analysis, run all three
python3 scripts/analyze_n_plus_one.py
python3 scripts/analyze_indexes.py
python3 scripts/analyze_config.py
Examine the output from each script, which categorizes issues by severity:
Create a prioritized list of actionable recommendations:
Critical Issues (fix immediately)
Performance Optimizations (high impact)
Best Practices (lower priority, preventative)
For index and schema recommendations, provide ready-to-use migration code:
class AddPerformanceIndexes < ActiveRecord::Migration[7.0]
def change
# Add foreign key index
add_index :posts, :user_id, algorithm: :concurrently
# Add partial index for boolean column
add_index :users, :active, where: "active = false", algorithm: :concurrently
# Add composite index
add_index :orders, [:status, :created_at], algorithm: :concurrently
end
end
Note: Use algorithm: :concurrently for production migrations to avoid locking tables.
When users need deeper understanding, refer them to:
references/performance_guide.md - Comprehensive best practices guidereferences/anti_patterns.md - Common mistakes and solutionsLoad these references when:
Run all three analysis scripts and provide a comprehensive report organized by priority.
Run analyze_n_plus_one.py and explain each detected issue with suggested fixes using includes, preload, or eager_load.
Run analyze_config.py and explain each configuration recommendation with context about why it matters.
Run index analysis and evaluate:
Don't just list issues - explain:
Reference specific chapters from "High Performance PostgreSQL for Rails" when relevant:
Not every detected issue requires immediate action. Help users prioritize:
Always provide concrete examples and migration code, not just abstract recommendations.
For deeper analysis beyond the scripts, manually review:
rails c to run EXPLAIN ANALYZE on slow queriesfind_each instead of eachThese analysis scripts use static analysis and may produce:
Always recommend:
Suggest complementary tools for ongoing monitoring:
When providing analysis results, use this format:
PostgreSQL Performance Analysis Report
=====================================
š Analysis Summary:
- Scanned X files
- Found Y issues
- Z high-priority recommendations
ā ļø CRITICAL ISSUES (fix immediately):
1. Missing foreign key index on posts.user_id
Impact: Slow joins, cascading delete performance
Fix: add_index :posts, :user_id, algorithm: :concurrently
2. N+1 query in PostsController#index
Impact: 1 + N queries instead of 2 queries
Fix: Use .includes(:user) on line 12
š” OPTIMIZATION OPPORTUNITIES:
1. Partial index for users.active column
Impact: Faster queries for inactive users
Fix: add_index :users, :active, where: "active = false"
š CONFIGURATION RECOMMENDATIONS:
1. Set statement_timeout to prevent runaway queries
Add to database.yml: statement_timeout: 30000
ā
BEST PRACTICES:
- Enable pg_stat_statements for query monitoring
- Consider adding counter caches for frequently counted associations
When using this skill in Claude Code:
python3, not python)This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.