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

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

    They definitely may give different results. The better one is

    select count(*) from pg_stat_activity;
    

    It's because it includes connections to WAL sender processes which are treated as regular connections and count towards max_connections.

    See max_wal_senders

提交回复
热议问题