PostgreSQL Connection Failed "No such file"

I have a simple Flask app that I’d like to connect to my postgres db.

When I connect to my db via: fly postgres connect -a vtu-db I successfully connect to psql and everything works.

When I fly ssh console --app vtu-db and type psql on the command line I get the following error:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket?

When I try accessing postgres from my app using the DATABASE_URL provided I get the same psql error as above.

I’ve tried a bunch of stuff but not really sure what is going on.

Here’s the contents of my .toml for reference:

primary_region = "sea"

builder = "paketobuildpacks/builder:base"

PORT = "8080"

internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

cpu_kind = "shared"
cpus = 1
memory_mb = 1024

Thanks for the help in advance!

This error is expected, as odd as it sounds at first, assuming that you typed psql with no arguments, :black_cat:. The reason is that the default port 5432 is actually the proxy in this setup—with the real Postgres server scooted over one (to port 5433):

fly ssh console --app vtu-db
su postgres
psql -p 5433  # not just for tcp, also determines the unix-domain socket (surprisingly)

This part is very unusual… Does it really mention a /var/run/ path?

Could you perhaps show us the DATABASE_URL, with the password removed?

1 Like

Really appreciate the help! Thanks for explaining the context, when I try using the proxy as you described it works!

After you cleared up the fact that my postgres was, in fact, working correctly I honed in on how I was trying to connect to the database in my app and I was incorrectly parsing DATABASE_URL.

All fixed, thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.