We have a production deployed Node js application which services a good amount of traffic throught the day. The application is in loopback and connects to postgres db as with its postgres connector. The connector leverages Node-Postgres as its pg client. We generally have kept max pool size as 50 and min as 5. There are three instances running on an average for the application.
The issue we are facing is that every now and then the application is unable to make a DB connection with error - reason: Error: timeout exceeded when trying to connect. We have tried to debug the same but there is no load on the DB while this happens - no cpu spike, no memory utilisation spike. FYI we use AWS Postgres RDS.
We have kept the following configuration as a part of connection parameters
connector: 'postgresql',
host: host,
user: user,
password: password,
database: database,
min: 5,
max: 50,
idleTimeoutMillis: 60000,
query_timeout: 5000,
connectionTimeoutMillis: 10000
Can someone please give us an idea why this can happen so frequently. Currently this is happening on a weekly basis. We are able to solve it only after application restart. This likely frees up the pool and terminates idle connections. But we are already doing it via application.