Find List of active user connections to PostgreSQL

If we want to get list of users connected to the PostgreSQL server, use system view pg_stat_activity. It contains information like database name,process id, username, application name, client ip address, query start time, which query user is running.

If we want to all information about all users connected to the PostgreSQL, run below query.

select * from pg_stat_activity;

Output:

Find List of active user connections to PostgreSQL

If we want to get the database name, username, process id, and query, then run the following query.

postgres=# select datname,usename,pid,query from pg_stat_activity; datname | usename | pid | query ----------+----------+-------+------------------------------------------------------------------------ postgres | anil | 57555 | postgres | postgres | 57110 | select datname,usename,pid,query from pg_stat_activity; bank | elchur | 57330 | c + | | | SELECT datname,usename,client_addr,client_port FROM pg_stat_activity ;

To check user connected to PostgreSQL?

select datname,usename,pid,query from pg_stat_activity where usename='anil';

Output:
datname | usename | pid | query
———-+———+——-+——-
postgres | anil | 57555 |
(1 row)

Related Posts

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: