Help us improve
Share bugs, ideas, or general feedback.
From ruby-rails
Analyzes PostgreSQL in Rails apps for N+1 queries, missing indexes, suboptimal configs, and anti-patterns. Runs scripts to detect issues and provides prioritized recommendations with migration code.
npx claudepluginhub el-feo/ai-context --plugin ruby-railsHow this skill is triggered — by the user, by Claude, or both
Slash command
/ruby-rails:postgresql-rails-analyzerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Analyze Rails applications for PostgreSQL performance issues and provide actionable optimization recommendations based on "High Performance PostgreSQL for Rails" best practices.
Analyzes Rails code for performance issues like N+1 queries, missing indexes, algorithmic bottlenecks, memory usage, and scalability. Use after implementing features or addressing slowdowns.
Reviews SQL queries for performance anti-patterns, missing indexes, N+1 queries, and unsafe operations. Analyzes raw SQL, ORM queries, and migration scripts for optimization.
Optimizes slow database queries via EXPLAIN (ANALYZE) analysis, index recommendations, N+1 detection, and ORM fixes for PostgreSQL, MySQL, Prisma, Django.
Share bugs, ideas, or general feedback.
Analyze Rails applications for PostgreSQL performance issues and provide actionable optimization recommendations based on "High Performance PostgreSQL for Rails" best practices.
Run from the Rails application root directory:
ruby scripts/analyze_n_plus_one.rb
Detects potential N+1 query issues by analyzing:
includes, preload, or eager_load callsruby scripts/analyze_indexes.rb
Identifies indexing opportunities:
ruby scripts/analyze_config.rb
Reviews database.yml for:
Clarify what the user wants to analyze: full performance audit, specific issue (slow queries, N+1 problems), configuration review, or schema optimization.
# For comprehensive analysis, run all three
ruby scripts/analyze_n_plus_one.rb
ruby scripts/analyze_indexes.rb
ruby scripts/analyze_config.rb
Script output categorizes issues by severity:
Create a prioritized list of actionable recommendations:
For index and schema recommendations, provide ready-to-use migration code. Use algorithm: :concurrently for production migrations to avoid locking tables.
class AddPerformanceIndexes < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def change
add_index :posts, :user_id, algorithm: :concurrently
add_index :users, :active, where: "active = false", algorithm: :concurrently
add_index :orders, [:status, :created_at], algorithm: :concurrently
end
end
Load these references when users need deeper understanding:
references/performance_guide.md — comprehensive best practices (indexes, queries, config, schema design, monitoring)references/anti_patterns.md — 25 common mistakes organized by category (queries, indexes, schema, config, transactions)For deeper analysis beyond the scripts, manually review:
rails c to run EXPLAIN ANALYZE on slow queries, check for sequential scans on large tablesfind_each instead of each)These analysis scripts use static analysis. They may produce false positives (flagging non-issues) or false negatives (missing runtime-only issues). Always recommend testing fixes in staging and using EXPLAIN ANALYZE to verify.
Suggest for ongoing monitoring: PgHero (dashboard), pg_stat_statements (query stats), Bullet gem (runtime N+1 detection), Rails query logging (development visibility).