How can you get the active users connected to a postgreSQL database via SQL? This could be the userid's or number of users.
This question is related to
sql
postgresql
active-users
Using balexandre's info:
SELECT usesysid, usename FROM pg_stat_activity;
OP asked for users connected to a particular database:
-- Who's currently connected to my_great_database?
SELECT * FROM pg_stat_activity
WHERE datname = 'my_great_database';
This gets you all sorts of juicy info (as others have mentioned) such as
usesysid
)usename
)appname
), if it bothers to set that variable -- psql
does :-)client_addr
)query
)Using balexandre's info:
SELECT usesysid, usename FROM pg_stat_activity;
OP asked for users connected to a particular database:
-- Who's currently connected to my_great_database?
SELECT * FROM pg_stat_activity
WHERE datname = 'my_great_database';
This gets you all sorts of juicy info (as others have mentioned) such as
usesysid
)usename
)appname
), if it bothers to set that variable -- psql
does :-)client_addr
)query
)Using balexandre's info:
SELECT usesysid, usename FROM pg_stat_activity;
Source: Stackoverflow.com