-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

PostgreSQL 10 Administration Cookbook

Here, we will show you how to learn whether a certain database user is currently connected to the database.
If you are logged in as a superuser you will have full access to monitoring information.
Issue the following query to see whether the bob
user is connected:
SELECT datname FROM pg_stat_activity WHERE usename = 'bob';
If this query returns any rows, then it means bob
is connected to the database. The returned value is the name of the database to which the user is connected.
PostgreSQL's pg_stat_activity
system view keeps track of all running PostgreSQL backends. This includes information such as the query that is being currently executed, or the last query that was executed by each backend; who is connected; when the connection, the transaction, and/or the query were started; and so on.
Please spend a few minutes reading the PostgreSQL documentation, which contains more detailed information about pg_stat_activity...