暂无图片
暂无图片
7
暂无图片
暂无图片
暂无图片

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

瀚高PG实验室 2022-01-06
15948

目录

环境

文档用途

详细信息



环境

系统平台:中标麒麟(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 行记录)

(左右滑动查看完整内容)



最后修改时间:2022-01-06 09:04:41
文章转载自瀚高PG实验室,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论