The following scripts are useful for getting the current sessions in PostgreSQL. This will list any active sessions along with user information.
-- Obtain a list of current, active sessions.
SELECT pid,
usename,
application_name,
client_addr,
client_port,
backend_start,
state
FROM pg_stat_activity
WHERE state = 'active';