问题

今天突然无法连接postgresql,出现的异常如下:

FATAL: sorry, too many clients already

解决

查看当前活跃和空闲连接

select pid, datname, application_name, client_addr, state from pg_stat_activity where state in ('idle', 'active');

根据条件清理空闲连接

select pg_terminate_backend(pid) from pg_stat_activity where state in ('idle') and client_addr = '192.234.23.4'; 

总结

根据ip清理多余的空闲连接,也可以根据连接名称来判断。查询postgresql默认配置最大连接数,如下:

show max_connections;

更多推荐