Skip to content

PostgreSQL, fix the `psql: error: could not connect to server` error

New Course Coming Soon:

Get Really Good at Git

I had this problem: I had installed PostgreSQL in the past using Homebrew, then I think I updated its version mindlessly with brew upgrade, and I couldn’t start it again.

It used to work, but now whenever I tried to access it, I got this error:

psql: error: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

The server was running fine, as ps aux | grep postgres showed its process.

I tried various solutions, until simply reinstalling it worked fine.

I ran

brew uninstall postgresql
brew install postgresql
brew services start postgresql

and I was able to connect to the database again.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching May 21, 2024. Join the waiting list!
→ Read my SQL Tutorial on The Valley of Code

Here is how can I help you: