Error: sorry, too many clients already

Error: sorry, too many clients already

我在我的 NodeJS 后端服务中使用 PostgreSQL。突然之间,当我启动服务时,我遇到了以下错误

 connection error error: sorry, too many clients already.

PostgresSQL 连接配置

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

由于上述错误,我无法查询数据库。我无法解决这个问题。能否请您提出解决方案

以下查询会对您有所帮助。

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

我遇到了同样的问题“抱歉,已经有太多客户端了。请求超时”。 我设法解决了它。 您可以尝试一些方法

1)第一个可以在sequilize中增加最大连接数和其他设置如

  { 
    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).第二种方法是使用 timescaledb,因为有时对于复杂的查询,我们会收到时间刻度数据的超时错误,您可以设置 timescaledb,这样您就可以 运行 复杂的数据库查询。 您还可以根据您的服务器要求为 postgres 设置最大客户端数。

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