Published on

PostgreSQL Error-sorry, too many clients already

Authors
  • avatar
    Name
    Lif
    Twitter

Error

PG的默认最大连接数是100.

如果超过100就会报错sorry, too many clients already

Find

show max_connections;
SELECT COUNT(*) from pg_stat_activity;
SELECT * FROM pg_stat_activity;

Solution

  1. 提高最大连接数
ALTER SYSTEM SET max_connections TO '6666'
然后重启pg
  1. 查看程序,减少从未关闭连接的函数
  2. 修改事务时间,减少事务未提交带来的问题
SET statement_timeout = 50000;   # 此处设置成50秒