普通用户登陆时出现报错信息:
psql: FATAL: remaining connection slots are reserved for non-replication superuser connections

原因:连接数已满

解决方法:
1. 管理员登录系统关闭空闲连接

# 查询当前所有连接的状态
postgres=# select datname,pid,usename,client_addr,application_name,state from pg_stat_activity;
 datname | pid  | usename |  client_addr   |    application_name    | state
---------+------+---------+----------------+------------------------+--------
         |  444 |         |                |                        |
         |  446 | nlpku   |                |                        |
 hrjlk   |  447 | hrjlk   | 172.24.105.173 | psql                   | idle
 hrjlk   | 1081 | hrjlk   | 172.24.105.172 | PostgreSQL JDBC Driver | idle
 hrjlk   | 1082 | hrjlk   | 172.24.105.172 | PostgreSQL JDBC Driver | idle
 hrjlk   | 1083 | hrjlk   | 172.24.105.172 | PostgreSQL JDBC Driver | idle
 hrjlk   | 1084 | hrjlk   | 172.24.105.172 | PostgreSQL JDBC Driver | idle
 hrjlk   | 1085 | hrjlk   | 172.24.105.172 | PostgreSQL JDBC Driver | idle
 hrjlk   | 1086 | hrjlk   | 172.24.105.172 | PostgreSQL JDBC Driver | idle


# 关闭空闲状态的连接(可通过pid进程关闭)
postgres=# select pg_terminate_backend(1086) from pg_stat_activity; 


# 查看数据库的最大连接数、当前连接数、剩余连接数
postgres=# select setting::int as max_connections,(select count(*) from pg_stat_activity) as current_connects,setting::int-(select count(*) from pg_stat_activity) as remain_connections from pg_settings where name = 'max_connections';
 max_connections | current_connects | remain_connections
-----------------+------------------+--------------------
            3000 |               34 |               2966
(1 row)


# 查看为超级用户保留的连接数: 
postgres=# show superuser_reserved_connections;
 superuser_reserved_connections
--------------------------------
 3
(1 row)

2. 修改最大连接数

# 打开postgresql配置文件(默认最大连接数100)
vi /data/pgsql/pgsql116/data/postgresql.conf
---------------------------------------------
max_connections = 3000

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐