Report this

What is the reason for this report?

How does my new Postgres DB have maxed out connections immediately after creation?

Posted on May 28, 2020

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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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:

  1. Ensure your application does not have processes that are running and keeping open connections.

  2. Scale up your instance size see link above with plan size and Available Backend Connection

  3. 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

  4. 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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.