0
点赞
收藏
分享

微信扫一扫

如何查看数据库当前连接数和最大连接数

目录
环境
文档用途
详细信息

环境
系统平台:中标麒麟(CPU龙芯)7,中标麒麟(CPU申威)7,中标麒麟(CPU海光)7,Linux x86-64 Red Hat Enterprise Linux 7
版本:6.0,5.6.5,4.5,4.5.2,4.3.4.9
文档用途
本文主要用于介绍查看数据库连接数方面的SQL语句。

详细信息
1、查看数据库当前连接数

select count(*) from pg_stat_activity;

[highgo@host1 ~]$ psql
Type "help" for help.
highgo=# select count(*) from pg_stat_activity ;
 count
-------
     6
(1 row)

2、查看数据库最大连接数,此数值包含为超级用户预留的连接数,详见第3部分

①登录数据库后通过语句查询

show max_connection;

highgo=# show max_connections ;
 max_connections
-----------------
 100
(1 row)

②查看postgresql.conf或postgresql.auto.conf文件

[highgo@host1 ~]$ cd $PGDATA
[highgo@host1 data]$ more postgresql.conf |grep max_connections
max_connections = 100   # (change requires restart)

3、superuser_reserved_connections

此参数为数据库为超级用户预留的连接数,默认值为3。当数据库的连接数达到(max_connections - superuser_reserved_connections)时,只有超级用户才能建立新的数据库连接,普通用户连接时将会返回错误信息“FATAL: sorry, too many clients already.”或者“FATAL: remaining connection slots are reserved for non-replication superuser connections”,登录数据库查询。

highgo=# show superuser_reserved_connections;
 superuser_reserved_connections
--------------------------------
 3
(1 行记录)
举报

相关推荐

0 条评论