Right query to get the current number of connections in a PostgreSQL DB

前端 未结 6 1584
暗喜
暗喜 2020-12-12 10:14

Which of the following two is more accurate?

select numbackends from pg_stat_database;

select count(*) from pg_stat_activity;
6条回答
  •  执笔经年
    2020-12-12 10:40

    Aggregation of all postgres sessions per their status (how many are idle, how many doing something...)

    select state, count(*) from pg_stat_activity  where pid <> pg_backend_pid() group by 1 order by 1;
    

提交回复
热议问题