psql: could not connect to server: No such file or directory (Mac OS X)
macos, postgresql
Solution
WARNING: If you delete postmaster.pid without making sure there are really no `postgres` processes running you, could permanently corrupt your database. (PostgreSQL should delete it automatically if the postmaster has exited.).
SOLUTION: This fixed the issue--I deleted this file, and then everything worked!
/usr/local/var/postgres/postmaster.pid
--
and here is how I figured out why this needed to be deleted.
I used the following command to see if there were any PG processes running. for me there were none, I couldn't even start the PG server:
ps auxw | grep post
I searched for the file .s.PGSQL.5432 that was in the error message above. i used the following command:
sudo find / -name .s.PGSQL.5432 -ls
this didn't show anything after searching my whole computer so the file didn't exist, but obviously `psql` "wanted it to" or "thought it was there".
I took a look at my server logs and saw the following error:
cat /usr/local/var/postgres/server.log
at the end of the server log I see the following error:
FATAL: pre-existing shared memory block (key 5432001, ID 65538) is still in use
HINT: If you're sure there are no old server processes still running, remove the shared memory block or just delete the file "postmaster.pid".
- Following the advice in the error message, I deleted the postmaster.pid file in the same directory as server.log. This resolved the issue and I was able to restart.
So, it seems that my macbook freezing and being hard-rebooted caused Postgres to think that it's processes were still running even after reboot. Deleting this file resolved. Lots of people have similar issues but most the answers had to do with file permissions, whereas in my case things were different.
Problem
Upon restarting my Mac I got the dreaded Postgres error: ``` 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"? ``` The reason this happened is because my macbook froze completely due to an unrelated issue and I had to do a hard reboot using the power button. After rebooting I couldn't start Postgres because of this error.
Related problems
- Can not connect to local PostgreSQL
- Postgresql adapter (pg): could not connect to server
- Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib
- Postgres could not connect to server
- FATAL ERROR lock file "postmaster.pid" already exists
- PG Error could not connect to server: Connection refused Is the server running on port 5432?
- Brew Postgresql Starts But Process Is Not Running