Thursday 21 October 2021

DigitalOcean - FATAL: remaining connection slots are reserved for non-replication superuser connections.

 We were getting this error on an App running on Digital Ocean.  

This is what you'll find if you Google the issue 

https://www.digitalocean.com/community/questions/fatal-remaining-connection-slots-are-reserved-for-non-replication-superuser-connections

You’ll need to Edit the PostgreSQL configuration file and increase the value for maxconnections. The value for sharedbuffers may also need to be increased.

You may see here how more connections have been created:


This setting would be changed at →

  1. Login to DigitalOcean – The developer cloud

  2. Click on ‘Databases’

  3. Click on your DB

  4. Click on the ‘Connection Pools’ tab


This led us to page showing that we have 22 connections that we could use.  So why are we using all our connection slots on digital ocean. 

AND OUR SITUATION IT WAS THE CODE AT FAULT. 

In the code there were 13 connections to the DB being opened but they were not being closed. 
What I needed to do is add the db.dispose() after the connections been used. 


db_engine = create_engine('[CONNECTION_DETAILS]', pool_pre_ping=True)
...
db_engine.dispose()


No comments: