App cannot connect to database

I’m currently exploring to migrate from Render → Fly. It’s a Phoenix project (albeit a little older so the default set-up wasn’t 100% compatible out of the box).

I’m hitting a snag now where my app is not able to connect to the database, this is the error message I’m seeing:

14:41:47.339 [error] Postgrex.Protocol (#PID<0.136.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (top2.nearest.of.slick-inbox-db.internal:5432): non-existing domain - :nxdomain

I can also confirm that I can connect to postgres directly with fly postgres -a slick-inbox-db connect, so it looks like the database is up and running. The DATABASE_URL is injected by Fly when I attached it to my app. I’ve also tried recreating the app & database, nothing really worked.

I saw a few other community threads here that suggested to run dig on the app instance - the thing is my app instance is not up, so fly ssh does not work:

$ fly apps list
slick-inbox                     personal        dead            nomad           1h22m ago
slick-inbox-db                  personal        deployed        machines                                       

What other debugging steps can I take here?

1 Like

This is probably an IPv6 issue. Give this a try: Legacy pre v1.6.3 Phoenix App · Fly Docs

I went through the guide again, and I’m still hitting the same issue. Any clues?

My now looks like this:

ip=$(grep fly-local-6pn /etc/hosts | cut -f 1)
export ELIXIR_ERL_OPTIONS="-proto_dist inet6_tcp"

Hi @edisonywh!

I’m guessing the problem is with this part of the config:


  config :hello_elixir, HelloElixir.Repo,
    # IMPORTANT: Or it won't find the DB server
    socket_options: [:inet6],
    url: database_url,
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

In particular is the :inet6 config.

Of course, update the settings for your app names.

1 Like

That was exactly it! Missed the socket option. Thanks Mark!

1 Like

Hi @Mark ! It’s @pdgonzalez872 from ElixirForum :heart:

I posted ( about this something similar in EF thread (

My setup was latest Elixir/Phoenix, all the bells and whistles :joy: Even bandit! :joy:

Like the EF post says, I tried creating a supabase db (tried Crunchy as well) and things just didn’t work out of the box. Maybe I’m missing something, but most importantly I just wanted to give you all a heads up about it.

I received an answer on Slack about this: Slack and maybe this is what folks are doing to overcome it? I figured you’d at least want this documented/known somewhere, so I hope this helps!

FYI if you tried this within the last half hour, Fly is currently having API downtime which seems to have taken out the Supabase integration. (At least my already-running database is now offline, which I assume is not a coincidence).

@bglw in my case, this is not the case. I was playing around last week with this stuff, haven’t gotten back to it since.

1 Like