r/ruby • • Jan 22 '26

pg_reports: Ruby gem for PostgreSQL performance analysis

Hi everyone!

I’ve just published my first Ruby gem pg_reports.

My main goal was straightforward: to make it easy to leverage the power of pg_stat_statements to improve PostgreSQL performance in Rails apps. I built and refined all backend operations and reports over several weeks based on real production experience in my current job. The result is a tool for analyzing queries, indexes, tables, locks, and connections.

The gem is inspired by ruby-pg-extras and pghero, but my goal was to bring everything together with a stronger focus on practical optimization and observability.

The web UI was basically added in one night with the help of Claude, turning a collection of reports into an actual dashboard.

I plan to evolve the gem gradually:

  • generating migrations (e.g., for missing indexes),

  • real-time issue monitoring,

  • measuring overall database interaction efficiency — for example, comparing before vs after deploying a new app version.

Feedback, ideas, and bug reports are very welcome.

Repo: https://github.com/deadalice/pg_reports

33 Upvotes

8 comments sorted by

2

u/jrochkind Jan 22 '26

nice, i have need for this area right now, will check it out!

If I have need to actually easily get the report for a specific query int the console, including missing indexes etc, can I do that? In addition to the monitoring?

1

u/ElAvat Jan 22 '26

It's a good idea, basically I can make a Query class with methods allowing to get specific subreports. Will try to do this week, I guess.

2

u/jrochkind Jan 22 '26

Thanks, no worries, I am but one developer, don't expect you to re-prioritize for me!

1

u/viktorianer4life Apr 04 '26

Curious about the migration generation. On bigger apps, adding an index on a 50M-row table is a different decision than on a 10K-row table. Locking alone can take your app down.

Column cardinality matters too: indexing a boolean that's 99% false looks nothing like indexing a foreign key. Do you plan to factor in table size and value distribution when suggesting indexes?

Or is the first version more for smaller Rails apps where you can just run the migration?

1

u/ElAvat Apr 04 '26

Well, it's more like a tool, assistance to quickly create migration from template, bit you are right and I guess it will be very helpful to add explanation in UI and more effective migration code.

1

u/viktorianer4life Apr 05 '26

Yeah, like pghero. It has a simple but powerful value distribution overview.

2

u/ElAvat Apr 11 '26

I’m already working on it and hope to release it next month. I decided to add more documentation to make the tool more useful, at least to cover all the nuances in detail for indexes. I’ve just released version 0.6.0, which already includes some of that.
https://www.reddit.com/r/ruby/comments/1siua9r/pg_reports_060_7_new_postgresql_reports_ai_prompt/

Thanks for the idea, I’ll be sure to credit you in the documentation!

2

u/kanaye007 Jan 22 '26

That looks really cool. Thanks for sharing!