By rosspatton
Hey so,
I’m currently building a site, and it’s currently not being shared too widely.
Recently, I setup a new DB via postgres managed connections, did a pg_dump, and connected to it. I’ve done this a couple times so far, with no issues.
Immediately, the site crashed. A quick inspection showed that the DB connection was maxed out at 150 connections.
I’m not particularly great at DB management, tbh, this is my first project where I’ve worked on the whole stack. How does this happen? And how would I fix it? I was thinking of setting up a connection pool, but honestly I shouldn’t have anywhere near enough traffic to require a pool quite yet.
Any help?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @rosspatton,
This error indicates you have maxed out the number of allowed connections to your PostgreSQL database.
The below link has information on the no of Available Backend Connection with the corresponding plan size
https://www.digitalocean.com/docs/databases/overview/#postgresql-limits
As a suggestion you can do one of the below to resolve the issue:
Ensure your application does not have processes that are running and keeping open connections.
Scale up your instance size see link above with plan size and Available Backend Connection
Look into connection pooling, see the link (https://www.digitalocean.com/docs/databases/how-to/postgresql/manage-connection-pools/) for connection pool information and how to create a connection pool
As a workaround you can setup a cronjob to close connections periodically
select pg_terminate_backend(procpid)
from pg_stat_activity
where usename = 'yourusername'
and current_query = '<IDLE>'
and query_start < current_timestamp - interval '3 minutes';
You can open a support ticket and reach out to DO support; If you require more details on managing connections for your Postgres database cluster.
https://docs.digitalocean.com/support/
I hope this helps!
Regards, Rajkishore
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.