1

I switched from exrm to distillery in build release for my phoenix project. Everything is working fine. when I do

iex -S mix phx.server

Application runs and everything gets connected with DB. but the build release not connecting with the database. (I think doing above command apart from build its getting dev values for db.)

2018-08-10 08:59:19.160 [error] Postgrex.Protocol (#PID<0.2803.0>) failed to connect: ** (Postgrex.Error) FATAL 53300 (too_many_connections): remaining connection slots are reserved for non-replication superuser connections

when I see /opt/evercam_media/releases/1.0.1/sys.config file it gives me the right values of Database which put there for DB connection

       {mode,prod}]},
  {'Elixir.EvercamMedia.Repo',
      [{adapter,'Elixir.Ecto.Adapters.Postgres'},
       {types,'Elixir.EvercamMedia.PostgresTypes'},
       {url,<<"postgres://localhost/evercam_dev">>},
       {socket_options,[{keepalive,true}]},
       {timeout,60000},
       {pool_timeout,60000},
       {pool_size,80},
       {lazy,false},
       {ssl,true}]},
  {'Elixir.EvercamMedia.SnapshotRepo',
      [{adapter,'Elixir.Ecto.Adapters.Postgres'},
       {url,<<"postgres://localhost/evercam_dev">>},
       {socket_options,[{keepalive,true}]},
       {timeout,60000},
       {pool_timeout,60000},
       {pool_size,100},
       {lazy,false},
       {ssl,true}]}]}].

what is the issue here? It's not getting connected with the database, what I am doing wrong?

Junaid Farooq
  • 2,484
  • 5
  • 26
  • 63
  • The issue is not it has wrong DB settings, the issue is your production DB is somehow overloaded with user connections, what is clearly said in the message. Do you own the database? Can you health-check it? At least restart the server? – Aleksei Matiushkin Aug 10 '18 at 07:26
  • the database is local on the server. as you can see `postgres://localhost/evercam_dev` yes i own the db. and no other application trying to connect it – Junaid Farooq Aug 10 '18 at 07:29
  • It usually means you do not disconnect properly and PostgeSQL expects you to disconnect clients. At the moment simple server restart should help. – Aleksei Matiushkin Aug 10 '18 at 07:32
  • I did but the results are same , I even restarted the whole server. – Junaid Farooq Aug 10 '18 at 07:37
  • Argh. I think I have it spotted: your production `ecto` has a not lazy pool of 80+100 workers and default PostgreSQL `max_connections` is AFAIR 100. Try to either decrease a pool size for `ecto` or increase the `max_connections` in `postgresql.conf` to 200+. – Aleksei Matiushkin Aug 10 '18 at 07:57

1 Answers1

0

The cause of this is your application has two repos, both using not lazy connection pools, of a total size of 180.

The default setting for PostgreSQL is 100 concurrent client connections.

You have two options:

increase max_connections setting in postgresql.conf to, say, 200

max_connections = 200
shared_buffers = 50MB

decrease ecto connection pools

config :ymy_app, EvercamMedia.Repo,
  adapter: Ecto.Adapters.Postgres,
  ...
  pool_size: 40

This answer might be useful as well.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160