右查询以获取PostgreSQL数据库中的当前连接数 [英] Right query to get the current number of connections in a PostgreSQL DB

查看:247
本文介绍了右查询以获取PostgreSQL数据库中的当前连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下哪两个更好?

select numbackends from pg_stat_database;

select count(*) from pg_stat_activity;


推荐答案

第一个的等效版本是:

SELECT sum(numbackends) FROM pg_stat_database;

在这种情况下,我期望版本比第二个略快,具有较少的行数。

In that case, I would expect that version to be slightly faster than the second one, simply because it has fewer rows to count. But you are not likely going to be able to measure a difference.

这两个查询都是基于完全相同的数据,因此它们同样准确。

Both queries are based on exactly the same data, so they will be equally accurate.

这篇关于右查询以获取PostgreSQL数据库中的当前连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆