Error: sorry, too many clients already

岁酱吖の 提交于 2019-12-02 17:24:58

问题


I am using PostgreSQL in my NodeJS backend service. All of sudden, when I start the service I am facing below error

 connection error error: sorry, too many clients already.

PostgresSQL connection config

 const pg = require(“pg”);
 const client = new pg.Client({
        host: “txslmxxxda6z”,
        user: “mom”,
        password: “mom”,
        db: “mom”,
        port: 5025
 });

I am unable to query database because of the above error. I am unable to fix this issue. Can you please suggest the solution


回答1:


below query will help you.

select max_conn,used,res_for_super,max_conn-used-res_for_super res_for_normal 
from 
  (select count(*) used from pg_stat_activity) t1,
  (select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) t2,
  (select setting::int max_conn from pg_settings where name=$$max_connections$$) t3



回答2:


I experienced the same issue that " sorry, too many clients already. Request timeout". I managed to solve it. There are some ways which you can try

1)The first one that you can increase the number of maximum connections and other settings in sequilize like

  { 
    max: 95,    //maximum connection which postgresql or mysql can intiate
    min: 0,     //maximum connection which postgresql or mysql can intiate
    acquire:20000, // time require to reconnect 
    idle: 20000, // get idle connection
    evict:10000 // it actualy removes the idle connection
   }

2). The second way is to use timescaledb because sometimes with complex queries we get timeout error for timescale data you can set timescaledb so you can run complex database queries. you can also set maximum clients for postgres according to your server requirement.

https://github.com/timescale/timescaledb-tune



来源:https://stackoverflow.com/questions/50947066/error-sorry-too-many-clients-already

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!