pg_stat_activity doesn't give you the real connections, it gives you the backends. Parallel executions would have multiple entries so your select should be like: select count(*) from pg_stat_activity where leader_pid is not null;
select count(*) from pg_stat_activity where leader_pid is not null;