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
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
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