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

前端 未结 6 1586
暗喜
暗喜 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:46

    The following query is very helpful

    select  * from
    (select count(*) used from pg_stat_activity) q1,
    (select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) q2,
    (select setting::int max_conn from pg_settings where name=$$max_connections$$) q3;
    

提交回复
热议问题