postgres show active 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';
SELECT * FROM pg_stat_activity;
SELECT * FROM pg_stat_activity WHERE datname='db_name';