PG数据库提示: FATAL: sorry, too many clients already

目录

场景:

idea启动提示如下错误

翻译:

连接数相关查询:

 原因分析:

解决方法:

场景:

idea启动提示如下错误

org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
    at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:463)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.(PgConnection.java:195)
    at org.postgresql.Driver.makeConnection(Driver.java:454)

翻译:

pg数据库已经有太多的客户端连接

连接数相关查询:

查询pg数据库设置的最大连接数 

show max_connections;

SELECT * FROM pg_settings  WHERE name = 'max_connections';

 查询pg数据库当前的连接数

--pg数据库当前连接数总数

SELECT sum(numbackends) FROM pg_stat_database;


---pg各个数据库中的连接数
SELECT datname, numbackends FROM pg_stat_database;

 查询pg某个数据库某个ip的连接数

SELECT datname,pid,state FROM pg_stat_activity  where datname = 'zwzt' and client_addr='192.168.100.88';

  关闭数据库中的空闲连接

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity    WHERE pg_stat_activity.datname = 'zwzt'

and client_addr='192.168.100.88' and state='idle'
and pid <> pg_backend_pid();

 原因分析:

当前数据库中的连接数1993,然而pg数据库设置的最大连接数是2000

PG数据库提示: FATAL: sorry, too many clients already_第1张图片

 pg数据库的最大连接数

PG数据库提示: FATAL: sorry, too many clients already_第2张图片

因此项目启动中很容易就超过了2000.

解决方法:

PG数据库提示: FATAL: sorry, too many clients already_第3张图片

 我把我ip连接的pg的空闲进程的连接都杀掉,再次启动就好了

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'zwzt' and client_addr='192.168.100.88' and state='idle'
AND pid <> pg_backend_pid();

你可能感兴趣的:(postgre,java,数据库,mybatis)