The following query is useful for getting the current sessions in PostgreSQL. It lists active sessions along with user and connection 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';