When I run the rake db:migrate
or run the rails s
command, I get the same error:
Error : could not connect to server:
No such file or
The exact same symptom can be caused by a stale lock file /var/run/postgresql/.s.PGSQL.5432.lock
. One of the symptoms of this is psql
reporting
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"?
even though there is clearly a socket with this path available as reported by netstat -lp --protocol=unix | grep postgres
The problem can be solved by removing the lock file and restarting postgresql. This is definitely less invasive than a purge and re-install.
sudo rm /var/run/postgresql/.s.PGSQL.5432.lock
sudo service postgresql restart