// the find
pawurb/rails-pg-extras
Rails PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.
A Rails gem that surfaces PostgreSQL internals — lock contention, index usage, buffer cache ratios, vacuum stats, bloat — through rake tasks and a Ruby API. It's a port of the Heroku PG Extras CLI, extended with a mountable web UI and an MCP interface for LLM-assisted analysis. Aimed at Rails developers who want visibility into a Postgres instance without writing pg_stat_* queries by hand.
The `diagnose` method runs a battery of checks and prints a structured report in one call — genuinely useful when you inherit a slow app and don't know where to start. The `measure_queries` helper is a nice addition over the Heroku original: it wraps any Ruby block and tells you query count, per-query timing, and what fraction of wall time was SQL, which makes N+1 debugging concrete. Multiple database support via `db_key` query param is handled cleanly with thread-local connection switching. The `missing_fk_constraints` heuristic correctly skips polymorphic associations, which is the main false-positive trap.
The gem requires `pg_stat_statements` for the most useful queries (`outliers`, `calls`) but that extension isn't on by default in many managed Postgres setups — you'll hit a confusing error if it's missing rather than a graceful degradation. The `bloat` query is a rough estimation based on page counts, not actual dead tuple counts; it's known to be unreliable on tables with lots of toast data or variable-width columns and can send you chasing phantom bloat. The web UI ships with a `kill_all` action that's disabled by default but mountable at any path with optional HTTP basic auth — in a multi-tenant or shared hosting scenario that's a footgun if the route is accidentally public. No support for partitioned tables; queries against `pg_stat_user_tables` will undercount on heavily partitioned schemas.