Can't connect to postgres through the fly proxy

This is for some reason not working for me

fly proxy 15432:5432 -a APP

psql postgres://USERNAME:PASSWORD@localhost:15432


psql postgres://USERNAME:PASSWORD@localhost:15432
psql: error: connection to server at "localhost" (::1), port 15432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (, port 15432 failed: FATAL:  database "pricing_livebook" does not exist

fly postgres connect --app APP --database DB
is working fine.

Am I doing something obviously wrong here?

I think you want fly proxy 15432:5432 -a <db-name> in the first example. postgres connect loads up a shell, proxy forwards the port so you can connect with other tools.

1 Like

Gah, sorry. Teach me to post right as dinner is called. :slight_smile: The proxy call is what I’m running that is then not working. I’ve fixed my question.

Oh that makes sense. :smiley:

Sorry to ask another obvious question, but are you letting the proxy command keep running while you try to connect? If you cancel that command the proxy stops, so you’ll need to psql from another terminal.

Ok, it wasn’t that. But I had attached a new app to an existing database, which generated a new username. And it appears that, because I had not specified a database in my psql command, that it was looking for one with the same name as my username. Adding the database name let the connection work.

The next problem was that I could connect, but not query the tables for lack of permissions. I had to grant those permissions explicitly to the new user. I can see how that might be the desired behavior, but it might be worth noting somewhere

Thanks @kurt

1 Like