This is a multi tenant question. I want to check how many users connected per database.
This query is the closest I have come:
SELECT datname, count(usesysid) as users
FROM pg_stat_activity
GROUP BY 1
But it seems not to be correct as the postgres db has 2 users and only 1 is logged in.
Is there any other way to figure out this?
It seems that every query in PGAdmin uses another process and acts like another user. So I can count processes but not "active users":
