Here, we will show you how to learn whether a certain database user is currently connected to the database.
Checking whether a user is connected
Getting ready
If you are logged in as a superuser, you will have full access to monitoring information.
How to do it…
Issue the following query to see whether the user bob is connected:
SELECT datname FROM pg_stat_activity WHERE usename = 'bob';
If this query returns any rows, then it that means bob is connected to the database. The returned value is the name of the database to which the user is...