Really helpful thread. Thanks, everyone.
I have a slight issue/annoyance…
The AC.Release
module has been generated by mix phx.gen.release --docker
to facilitate running of migrations in the production Docker environment.
AC.Release module
defmodule AC.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
@app :ac
def migrate do
load_app()
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
Application.load(@app)
end
end
The Dockerfile CMD
points to a shell script in rel/overlays
:
cd -P -- "$(dirname -- "$0")"
./ac eval AC.Release.migrate && PHX_SERVER=true exec ./ac start
I’ve found that unless I add queue_target
to the Repo options (currently at 2_000
), I get a connection error:
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2505ms. This means requests are coming in and your connection pool cannot serve them fast enough.
When queue_timeout
is/was not set in config, I don’t get the error when running the app, and I was able to run the migrations when connected to the app with the ./ac remote
command using AC.Release.migrate()
just fine.
I suppose I can simply leave queue_timeout
there, but does anyone have any idea why it’s necessary when running ./ac eval AC.Release.migrate
but not when running the app?
I’m running at Northflank, with a 512MB RAM PostgreSQL service, with no real app data or load. Apparently, the maximum number of concurrent connections is 64. I’ve played with the pool_size
option for both the Repo config and Ecto.Migrator.with_repo/3
, giving them both 20 at one point, seemingly making no difference.
I can successfully connect to the database via psql
using the same database URL as that in use by the Repo config.
Thanks.