We seem to be getting the following error was frequently whilst there might be three at most working on this in development at one time.
error: remaining connection slots are reserved for non-replication superuser connections. sorry, too many clients already
We’re using PostgreSQL and DigitalOcean Managed Databases.
I did explore setting up a pool but then when deploying this with Strapi, Strapi said that cross-database references are not implemented.
I’m not sure exactly what the issue is but I don’t seem to have problems like this when using a local database (I know I’m the only connection). It’s just we opted for Managed Databases because of the simplicity of managing them.
I am also having this problem with Google Cloud SQL. Will try setting up connection pooling as outlined above and let you know if that works.
Edit: It seems to have worked so far! Having to add connection pooling to the options may be caused by using a ‘low’ memory Cloud SQL server (~0.6gb) which restricts the max_connections flag to 25. It may be good to add this stipulation to the Google Cloud hosting guide. I can propose an edit to it in a few days if nobody has by then.
the limit was still being hit. I ended up configuring the instance to use 1.7 GB of memory (and ensured that the max_connections was 50) and that seems to have solved the problem so far.
This week my website went down twice because of this error (using postgres on aws - rds)
I had setup the pooling to support max connections of 50. Then I went to check the status and realize that, twice, it went over the 50. Does someone has faced this already?
Thank you so much for your comments here. It means a lot.
the limit was still being hit. I ended up configuring the instance to use 1.7 GB of memory (and ensured that the max_connections was 50) and that seems to have solved the problem so far.
So I was having the same problem when deploying Strapi to Google Cloud Run, and it turns out that Cloud Run was keeping a connection alive for every successful revision (a.k.a. every time I deployed successfully to Cloud Run). Hence I had dozens of connections alive.
I know Cloud Run keeps the connection alive to balance traffic among revisions, but in this case it was swamping my connections with inactive instances. Once I removed the revisions the problem stopped.
I do not know if App Engine works the same by keeping a connection alive for every successful deployment, but it might be worth to check if the cloud service employed keeps connections of past deployments alive as in the case of Cloud Run.
I had the same issue and this comment helped me a lot. I’m on strapi v3, on digitalocean apps platform and using DO’s managed databases running postgres v14.
I did include the pool config to my database.js file inside strapi config fodler and increased the db RAM from 1gb to 2gb. Could not connect to digital ocean’s Connection Pools though, strapi kept crashing saying that cross-database references was not configured and I couldn’t manage to make it work, so I just reverted back to connecting directly to my pg db.
Last thing I recommend ( according to knex.js docs ) that you set pool.min : 0 that means that tarn.js (what knex uses to manage pooling) will terminate all idle connections, preventing this error to happen again.