Often, several different processes may connect as the same database user. In that case, you may actually want to know whether there is a connection from a specific computer.
Checking whether a computer is connected
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;
The client_addr and client_port parameters...