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?

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