pawurb / ruby-pg-extras

Ruby PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.
MIT License
124 stars 11 forks source link

All Locks "age" accuracy and including `pg_stat_activity.application_name` #7

Closed bensheldon closed 2 years ago

bensheldon commented 2 years ago

This is a really helpful gem! I'm the author of GoodJob, which uses a lot of Advisory Locks. This gem (and rails-pg-extras) came up in an issue (https://github.com/bensheldon/good_job/issues/480).

For Advisory Locks in all_locks, the age isn't accurate because the query is fetching the time of the connection's last query, not necessarily the age of the Advisory Lock itself:

https://github.com/pawurb/ruby-pg-extras/blob/1e2a33ea27ecb955ad09b75d1a7dcd20c8f9bc10/lib/ruby-pg-extras/queries/all_locks.sql#L10

I wanted to suggest renaming it, maybe last_activity_age (naming is hard).

And, I also wanted to suggest including pg_stat_activity.application_name in the output. I think that application_name can provide high-context information that would be really useful for understanding what's happening with the locks.

pawurb commented 2 years ago

@bensheldon thanks for suggestion, sorry I missed it. I'd rather not changing names because it would require a major release. But would be great if you would submit a PR adding application_name to locks.