postgres see connections code example
Example 1: psql connections
SELECT * FROM pg_stat_activity;
Example 2: check connections to database postgres
SELECT * FROM pg_stat_activity WHERE datname='db_name';
Example 3: postgresql print sessions using the database
select pid as process_id,
usename as username,
datname as database_name,
client_addr as client_address,
application_name,
backend_start,
state,
state_change
from pg_stat_activity;