Problems with Postgres Addon
-
I have built an app in Elixir 1.17.2 and would love to use Cloudron's postgres addon, but I am facing some problems that I don't have on localhost, specifically the two below. I would appreciate some ideas how to debug this:
11:16:27.216 [error] Postgrex.Protocol (#PID<0.437.0>) failed to connect: ** (Postgrex.Error) FATAL 53300 (too_many_connections) too many connections for database "db72c357c2ba3f4121a9fc5d9be2cd97bb" 11:16:27.216 [error] Postgrex.Protocol (#PID<0.425.0>) failed to connect: ** (Postgrex.Error) FATAL 53300 (too_many_connections) too many connections for database "db72c357c2ba3f4121a9fc5d9be2cd97bb" 11:16:27.298 [error] Failed to start Ranch listener APP.Endpoint.HTTP in :ranch_tcp:listen([cacerts: :..., key: :..., cert: :..., port: 4001]) for reason :eaddrinuse (address already in use) 11:16:27.304 [error] Running APP.Endpoint with cowboy 2.12.0 at http failed, port already in use 11:16:27.306 [notice] Application APP exited: APP.Application.start(:normal, []) returned an error: shutdown: failed to start child: APP.Endpoint ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, APP.Endpoint.HTTP} ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup ** (EXIT) {:listen_error, APP.Endpoint.HTTP, :eaddrinuse} ** (exit) :terminating (kernel 10.0.1) application_controller.erl:511: :application_controller.call/2 (kernel 10.0.1) application.erl:367: :application."-ensure_all_started/3-lc$^0/1-0-"/1 (kernel 10.0.1) application.erl:367: :application.ensure_all_started/3 (mix 1.17.2) lib/mix/tasks/app.start.ex:72: Mix.Tasks.App.Start.start/3 (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5 (mix 1.17.2) lib/mix/tasks/run.ex:129: Mix.Tasks.Run.run/5 (mix 1.17.2) lib/mix/tasks/run.ex:85: Mix.Tasks.Run.run/1 (mix 1.17.2) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
So, specifically:
- Postgres shows the max. connections are used
- The port appears to be occupied, but I don't understand where. I tried already using a different port.
In accordance to the tutorial how to connect to your postgres database on Cloudron, I tried this:
To connect via PostgreSQL CLI, open a Web Terminal and click the PostgreSQL button at the top. This will paste the CLI connection command into the Web Terminal. Press enter to execute the command and use the CLI.
but it shows this: bash: psql: command not found
The environment variables are set (check with env | grep CLOUDRON_POSTGRESQL)
The cloudron manifest sets the postgres addon like this:
"addons": { "localstorage": {}, "postgresql": {} },
I would appreciate some ideas how I could resolve this.
-
Did you use the Cloudron base image for your app (Maybe post your repository URL or the Dockerfile)? It reads like you did not, and that is why the Cloudron default tools are missing.
-
Looks like maybe the app keeps crashing after keeping open connections to postgres. Postgres has an internal counter of connections and if they are not closed periodically, it will block that client. You can simply restart postgres (services -> postgres -> restart) and it will start accepting.
Not sure about eaddinuse. But usually this means someone else is listening on that port (maybe again related to app restart/crash)
-
@BrutalBirdie said in Problems with Postgres Addon:
Did you use the Cloudron base image for your app (Maybe post your repository URL or the Dockerfile)? It reads like you did not, and that is why the Cloudron default tools are missing.
I did not think of that! However, using it didn't solve the problem either.
@girish said in Problems with Postgres Addon:
Looks like maybe the app keeps crashing after keeping open connections to postgres. Postgres has an internal counter of connections and if they are not closed periodically, it will block that client. You can simply restart postgres (services -> postgres -> restart) and it will start accepting.
Not sure about eaddinuse. But usually this means someone else is listening on that port (maybe again related to app restart/crash)
I can't see that the app keeps crashing. At least I can access its frontend normally, which also irritates me regarding the port error.
I am pooling connections and I am well below the number of max connections allowed.I really don't know why the database error happens only on Cloudron but not locally.
-
I solved the port issue as well.
The problem occured when I tried to start an interactive shell, which counted as starting a second application inside the cloudron app, that's where the port conflict came from.If someone else is working with Elixir on Cloudron, you can start an interactive shell like this:
/app/_build/prod/rel/APP/bin/APP remote