Checking whether a computer is connected
Often, several different processes may connect as the same database user. In that case, you may want to know whether there is a connection from a specific computer.
How to do it…
You can get this information from the pg_stat_activity
view as it includes the connected clients' IP address, port, and hostname (where applicable). The port is only needed if you have more than one connection from the same client computer and you need to do further digging to see which process there connects to which database. Run the following command:
SELECT datname, usename, client_addr, client_port, application_name FROM pg_stat_activity WHERE backend_type = 'client backend';
The client_addr
and client_port
parameters help you look up the exact computer and even the process on that computer that has connected to the specific database. You can...