Postgres 最大连接数满了: remaining connection slots are reserved for non-replication superuser connections
pg_stat_activity
最近遇到链接pg数据库报错:remaining connection slots are reserved for non-replication superuser connections。百度说,是由于设置的最大连接数满了,解决办法都是改最大连接数,或者杀掉状态为idle的链接。设计到的sql查询如下:
查询当前所有空闲链接:
select datname,pid,application_name,state from pg_stat_activity where state=‘idle’ ;
查询当前所有连接数:
select count(1) from pg_stat_activity;
查询最大连接数:
show max_connections;
select current_setting(‘max_connections’);
终止空闲链接
select pg_terminate_backend(pid) from pg_stat_activity where pid<>pg_backend_pid() and state=‘idle’;
查看为超级用户保留的连接数:
show superuser_reserved_connections;
查看每个用户的而连接数:
select usename, count() from pg_stat_activity group by usename order by count() desc;
查看数据库剩余连接数:
select max_conn-now_conn as resi_conn from (select setting::int8 as max_conn,(select count(*) from pg_stat_activity) as now_conn from pg_settings where name = ‘max_connections’) t;
refer to: https://www.cnblogs.com/shuangmeier/p/16426667.html
更多推荐
所有评论(0)