Fix local error with postgreSQL when starting rails app

22 Mars 2024

This week, I had to solve a problem related to PostgreSQL. I was unable to launch or deploy my Rails applications that used PostgreSQL.

More precisely, locally, the application would start and then display an error during loading.

The error in question:

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


After some research on Stack Overflow and others, I was able to find some advice like:

brew uninstall postgres
brew install postgres
brew services restart postgres


rm -rf /usr/local/var/postgres/postmaster.pid


As you can guess, it was not as simple as a restart.


The solution


After uninstalling and then installing different versions, I decided to look into the paths /usr/...

In my configuration, at /usr/local/var/, I had several Postgres folders, postgres@13, postgres@14, etc. There was no trace of the postmaster.pid file in these folders. So, I tried deleting these folders to be able to reinstall PostgreSQL, and this approach worked.


!! Caution, this approach will delete all your local databases !!


The process that allowed me to solve the problem:


rm -rf /usr/local/var/postgres
rm -rf /usr/local/var/postgres@13
....

then

brew install postgres