However after doing this I get errors in my application saying that it was unable to connect.
I think the issue may be related to fly’s private networking as the page says this:
Note that for the app to be able to attach to the database it must have private_network enabled in fly.toml . This enables it to look up .internal addresses like the database URL. See Using Fly DNS for further details.
Unfortunately the page linked for more information about the private_network config option doesn’t actually mention private_network, so I’m not sure what to do next. It’s also not included in this page on fly.toml: Fly Launch configuration (fly.toml) · Fly Docs
How might I resolve this issue and connect to the PostgreSQL instance from my application? It would be grand to get all the steps required to connect to PostgreSQL added to this page: Fly Postgres · Fly Docs
Unfortunately the Erlang PostgreSQL client I’m using doesn’t seem to give an error beyond the atom none_available when you attempt to checkout a connection.
Looks like I’m going to have to do some digging and see how I can replicate that Elixir config in the Erlang world.
One thing you can try is using an IP address directly. If you run fly dig aaaa <dbname>.internal -a <appname> you’ll get a list of IPv6 addresses back. Connecting directly to any of those will bypass the DNS lookup.
Fab, thanks. I tried putting the IP address as the value for the database client’s host parameter which unfortunately didn’t work.
It doesn’t seem like there’s a way to specify socket options for this library, so I might be stuck. I’ve opened a issue with the project, hopefully they’ll get back to me.
In the mean time is it possible to connect to PostgreSQL over an IPv4 public network? Similar to how Heroku and Render’s managed PostgreSQL?
It’s obviously a much worse solution, but I’m not sure how long it might before I’ll be able to use IPv6 here and it’d be grand to publish this Gleam + PostgreSQL + Fly demo app sooner rather than later.
You can expose Postgres over a public IP but we really, really don’t suggest it. You’re much better off running a proxy with your app processes if it’s easy.
I think that’d be good for a real project, but for an example application I think it might distract from the content I actually want to show. I wouldn’t want to give the impression that you need to know how to install and configure haproxy to use this collection of technologies.
I think I may have to dig into the Erlang client (though not right now, I’m feeling a little under the weather )
We’ve got the database client connecting to a local postgresql instance listening on ::1, so IPv6 seems to be working.
Unfortunately I’m still not able to connect on Fly. I created an application using this Erlang client and also the Elixir Postgrex one and the Elixir one succeeded while the Erlang one didn’t. Could there be something else beyond IPv6 here?
Edit: I’ve added some more logging and discovered an error message that was being discarded