postgresql-rails-analyzer

Analyze Rails applications for PostgreSQL performance issues and anti-patterns.

12|2|Updated Mar 11, 2025
One-click install
npx skills add https://github.com/el-feo/ai-context --skill postgresql-rails-analyzer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: postgresql-rails-analyzer
Source: https://github.com/el-feo/ai-context/tree/main/skills/postgresql-rails-analyzer
Command: npx skills add https://github.com/el-feo/ai-context --skill postgresql-rails-analyzer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires PyYAML, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps Rails teams quickly identify PostgreSQL performance issues in a Rails codebase, including slow queries, N+1 problems, missing indexes, and suboptimal configurations. It delivers actionable recommendations to optimize database performance and reliability.

Core Features & Use Cases

  • N+1 Query Detection: Analyze controllers, views and models to surface N+1 patterns and suggest eager loading strategies.
  • Index Opportunity Identification: Inspect migrations/schema to find missing indexes and recommend concrete indexing improvements.
  • Configuration Review: Evaluate database.yml settings for connection pooling, timeouts, prepared statements, and SSL to reduce connection overhead and prevent runaway queries.
  • Use Case: Run a full audit when users request "analyze the database", "check for N+1 queries", or "optimize PostgreSQL" in a Rails app.

Quick Start

From the Rails project root, run:

  • python3 scripts/analyze_n_plus_one.py
  • python3 scripts/analyze_indexes.py
  • python3 scripts/analyze_config.py

Frequently Asked Questions about postgresql-rails-analyzer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect N+1 queries in my Rails application?

N+1 queries occur when your Rails code executes one query to fetch records, then additional queries for each record's associations. Use eager loading with `includes`, `preload`, or `joins` in your queries, and run the N+1 analysis script to identify patterns in controllers, views, and models that trigger this anti-pattern.

What PostgreSQL performance issues can I find in a Rails codebase?

PostgreSQL performance audits in Rails applications reveal slow queries, N+1 patterns, missing indexes, suboptimal connection pooling, and configuration gaps in database.yml. This Skill analyzes migrations and schema to recommend concrete indexing improvements and configuration tuning to reduce connection overhead.

How do I identify missing database indexes in Rails migrations?

Missing indexes slow down queries by forcing full table scans. Inspect your schema and migration files to find columns frequently used in WHERE clauses, JOINs, or foreign keys that lack indexes. This Skill generates ready-to-use Rails migration code to add recommended indexes.

Can I optimize database.yml settings to improve Rails PostgreSQL performance?

Yes. Review connection pooling, timeout settings, prepared statements, and SSL configuration in database.yml to reduce connection overhead and prevent runaway queries. The Skill evaluates these settings and recommends adjustments for your Rails environment.

What's the best way to audit a Rails application for database performance issues?

Run a full audit from your Rails project root using the analysis scripts to detect N+1 queries, find missing indexes, and review database configuration. The Skill delivers actionable recommendations and generates migration code for schema improvements based on PostgreSQL best practices.

Does this work with large Rails codebases requiring performance reviews?

Yes. This Skill applies to Rails applications of any size that need performance audits, database tuning, and codebase reviews. It surfaces anti-patterns and provides concrete recommendations to optimize PostgreSQL queries and schema design.