I’m trying out Fly’s managed db but I can’t get it to connect with the Phoenix application. I tried using the clustered live counter (elixir-hiring-project/releases.exs at main · superfly/elixir-hiring-project · GitHub) but it doesn’t seem to have db-related configuration.
Error message:
[error] Postgrex.Protocol (#PID<0.379.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (app-postgres.internal:5432): non-existing domain - :nxdomain
I’m certain that the DATABASE_URL
was set properly since I managed to log it. The database was created through flyctl postgres create -a app_name --postgres-app postgres_name
. I also tried using the postgres
user and password with the database name appended to the postgres URL. Nothing works. So this leads me to believe that it may be related to how the db cluster was orchestrated. But I’m not sure.
The app instance, and db cluster are also in the same organization. However, in different regions since I ran into an error where I’m only allowed to run one app in a region.
# config/runtime.exs
import Config
if config_env() == :prod do
database_url =
System.get_env("DATABASE_URL") ||
raise """
environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE
"""
secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise """
environment variable SECRET_KEY_BASE is missing.
You can generate one by calling: mix phx.gen.secret
"""
config :app, App.Repo,
ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
config :app, AppWeb.Endpoint,
server: true,
http: [
port: String.to_integer(System.get_env("PORT") || "4000"),
transport_options: [socket_opts: [:inet6]]
],
secret_key_base: secret_key_base
end
#config/prod.exs
use Mix.Config
config :app, AppWeb.Endpoint,
load_from_system_env: true,
http: [port: {:system, "PORT"}],
url: [host: "***.fly.dev", port: 443], # Intentionally omitted
force_ssl: [rewrite_on: [:x_forwarded_proto]],
cache_static_manifest: "priv/static/cache_manifest.json"
Any pointers would be great! I’ve been stuck with this for 4 hours.