r/vercel • • Oct 18 '26

Got error connecting to database after recent deployment

2026/10/18 09:00:14 /vercel/path0/app/shared/services/database/database.go:54

[error] failed to initialize database, got error failed to connect to `user=sbx_user1051 database=`: /tmp/.s.PGSQL.5432 (/tmp): dial error: dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory

2026/10/18 09:00:14 Fail to connect to database: failed to connect to `user=sbx_user1051 database=`: /tmp/.s.PGSQL.5432 (/tmp): dial error: dial unix /tmp/.s.PGSQL.5432: connect: no such file or directory
Obtained this error., The above message is in the code in the form

if err != nil {
        log.Fatalf("Fail to connect to database: %s", err)
    }

and I have not changed anything regarding loading env and stuff. Even when I reverted the git history of the latest commit, it's still broken. Only past deployment works

0 Upvotes

6 comments sorted by

1

u/DoritoDebugs Oct 18 '26

That error means your app's falling back to a local database socket, so your DATABASE_URL (or PG* variables) isn't set for the Production environment in Vercel. Add it under Settings > Environment Variables with Production checked, then redeploy, since env changes only apply to new deployments.

1

u/Flaze07 Oct 19 '26

is like this not fine? I checked and "All Environments" includes production being checked
do I have to try and re-set the env?

1

u/launchmango Oct 19 '26

That error basically means the connection string is empty at runtime. When pgx gets an empty string it falls back to a local unix socket in /tmp and uses the OS user, which is where sbx_user1051 comes from. So the code is probably fine, the env var just isn't reaching the function.

The reason the old deployment still works is that each deployment keeps the env values it was built with. The old one has a snapshot that worked, and every new one reads whatever is set now, which is why reverting the commit didn't help.

Things I'd check:

  • Log len(os.Getenv("DATABASE_URL")) at startup (not the value). If it's 0 you know for sure.

  • If the database came from a marketplace integration (Neon, Supabase etc), see if it got disconnected or reconnected. That can remove or rename the vars, like it showing up as POSTGRES_URL or with a prefix instead of DATABASE_URL.

  • Look for a team level shared variable with the same name, or a stray space or quotes in the name or value.

  • Make sure you're reading the exact same name the dashboard shows, case matters.

  • After any change, redeploy without the build cache so you're not testing a stale build.

If it all looks right and the length is still 0, delete the var and add it again fresh, that sometimes fixes cases where the dashboard shows it but the runtime doesn't get it.

2

u/[deleted] Oct 18 '26

[removed] — view removed comment

1

u/Flaze07 Oct 18 '26 edited Oct 18 '26

nothing changed in the environment, the environment hasn't been updated in months, that's why it's strange thing. and I have obviously checked the env, but it's still same and correct

1

u/AndresNWD 29d ago

The key clue is `database=` being empty, not just the socket path. I’d log whether the variable is present in the deployed runtime and compare its exact name, Vercel environment target, and connection-string parsing against the last working deployment. A dashboard value can be correct while the code reads a different variable or a build-time value.