Why are there so many connections in Postgres?

I am finding bits and pieces of this solution everywhere, but nothing is matching my situation.

I am trying to deploy a site using docker, and connecting to a digital ocean postgres account. I have the smallest account possible, 1GB ram, which seems like it should be fine for starting up an application with no users yet.

When I try to run the container locally, I get flooded with the following error:

Postgrex.Protocol (#PID<0.1907.0>) failed to connect: ** (Postgrex.Error) FATAL 53300 (too_many_connections) remaining connection slots are reserved for non-replication superuser connections

my current pool_size is set to 10.

when I check the connections (nothing is attached to this database that I can tell), I get

select max_conn,used,res_for_super,max_conn-used-res_for_super
    res_for_normal
from
    (select count(*) used from pg_stat_activity) t1,
    (select setting::int res_for_super from pg_settings where
            name='superuser_reserved_connections') t2,
    (select setting::int max_conn from pg_settings where name='max_connections') t3

max conn = 25
used = 25

If i look at the insights tab in digital ocean, it shows a consistent 15 connections, all day and night.

Am i missing something in my configuration? Is there a way to clear all of those connections to troubleshoot?

I did try setting up a connection pool, but got the same errors.

Thanks!

Nothing comes to mind but it does seem like something you’re not aware of is using the database. Have you tried simply stopping the DB and then restarting it, and then immediately start your Elixir app after that?

1 Like

(Edit: rereading your message I see you already gave the info I ask for :slight_smile: changed my message accordingly)

How much conns are in use when you turn off the app completely?

Are you using any kind of other library inside your app that could be spawning the conns?

Maybe you could connect on a remote shell in your app and explore from there? Listing the actual runtime config of ecto for example?