Postgres max connections

I tried scaling up our bg-processing service and got a bunch of “remaining connection slots are reserved for non-replication superuser connections”. Found a similar thread here, but no useful info on what to do. Please advise.

If I have 3 workers each with 20 threads that is 120 connections, this can happen on a deploy when old workers are still active and new ones are already spawned.

Hey Honza,

Databases have a 97 connection limit. When Render deploys a new version of your service with multiple instances, it will only create one new instance at a time before taking down an old instance. So you should never have more than 4 instances using the connections at once. Is it possible that a different service is using a high number of connections as well?

I only had the bg workers with 20 threads each and a front-end service with 4(worker)*5(thread) connections.

4(worker)*5(thread) means 20 total connections, correct? If so, this would put you just over the 97 connection limit since you would have (3 old workers * 20 connections) + (1 new worker * 20 connections) + (4 front end workers * 5 connections) = 100 connections.

Can you slightly reduce the thread count on any of these workers to stay under the limit during a deploy?

yes that is what I did for now