Connecting phoenix app to external database?

I try to connect my fly app with an external db. but I get:

[error] Postgrex.Protocol (#PID<0.166.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

I am a bit confused because it says localhost no matter what I set the DATABASE_URL to. I tried it with supabase, a fly pg and a postgres on hetzner. None worked.

When I run it locally with PHX_SERVER=true _build/.../bin/myapp start everything works just fine.

I always run into this kind of issue with fly (and according to search results plenty of others too), so I feel like I’m missing an important piece of information to make this work on fly.

Can you post the output from Application.get_env(:my_app, MyApp.Repo)?