Skip to content

Add user to pg_stat_activity #737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dusatvoj opened this issue Dec 28, 2022 · 3 comments
Closed

Add user to pg_stat_activity #737

dusatvoj opened this issue Dec 28, 2022 · 3 comments

Comments

@dusatvoj
Copy link

dusatvoj commented Dec 28, 2022

Proposal

Hello, I'm missing support to count connections to the database per-user. It's nice to see connections per database but when you have multiple users accessing to the database, you can't decide which one is the most consuming one.

You can count by datname, like this:
image
But you can't count by usename and datname, like this:

postgres=# select usename, datname, count(*) from pg_stat_activity group by usename,datname;
      usename      |    datname    | count 
-------------------+---------------+-------
 postgres          | mydb          |     1
 mydb              | mydb          |    15
 postgres_exporter | postgres      |     2
 analytics         | mydb          |     2
 postgres          | postgres      |     1
 postgres_exporter | mydb2         |     1
 mydb              | postgres      |     1
 postfix           | mydb          |     1
 postgres_exporter | mydb          |     1
(9 rows)

Yes, I can do it via custom queries, but I think the right approach is via core pg_stat_activity_.* metric stuff.

Maybe the easiest way is to add usename label to pg_stat_activity_count and add usename to group by.

Thank you

@TimDurward
Copy link

@dusatvoj I was looking for this feature as well, looks like it was implemented though, just hasn't been released/built yet.
#673

@dalbani
Copy link

dalbani commented Mar 30, 2023

@dusatvoj Did you try with the new released version 0.12.0 of the exporter? It contains the commit/feature in question.

@dusatvoj
Copy link
Author

Nope. Ok, closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants