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

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

    From looking at the source code, it seems like the pg_stat_database query gives you the number of connections to the current database for all users. On the other hand, the pg_stat_activity query gives the number of connections to the current database for the querying user only.

提交回复
热议问题