I'm trying to run psql
on my Vagrant machine, but I get this 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"?
Note: Vagrant 1.9.2 Box: ubuntu/trusty64, https://atlas.hashicorp.com/ubuntu/boxes/trusty64
EDIT Commands I've used in order to install and run postgres:
sudo apt-get update
sudo apt-get install postgresql
sudo su postgres
psql -d postgres -U postgres
I am just posting this for anyone who is feeling lost and hopeless as I did when I found this question. It seems that sometimes by editing some psotgresql-related config files, one can accidentally change the permissions of the file:
Note how pg_hba.conf belongs to root, and users cannot even read it. This causes postgres to not be able to open this file and therefore not be able to start the server, throwing the error seen in the original question.
By running
sudo chmod +r pg_hba.conf
I was able to make this file once again accessible to the postgres user and then after running
sudo service postgresql start
Was able to get the server running again.
The same thing happened to me as I had changed something in the
/etc/hosts
file. After changing it back to127.0.0.1 localhost
it worked for me.I've had this same issue, related to the configuration of my pg_hba.conf file (located in
/etc/postgresql/9.6/main
). Please note that 9.6 is the postgresql version I am using.The error itself is related to a misconfiguration of postgresql, which causes the server to crash before it starts.
I would suggest following these instructions:
sudo service postgresql start
pg_lsclusters
from your terminalCheck what is the cluster you are running, the output should be something like:
Version - Cluster Port Status Owner Data directory
9.6 ------- main -- 5432 online postgres /var/lib/postgresql/9.6/main
pg_ctlcluster <version> <cluster> start
, so in my case, using version 9.6 and cluster 'main', it would bepg_ctlcluster 9.6 main start
/var/log/postgresql/postgresql-<version>-main.log
, so in my case, the full command would besudo nano /var/log/postgresql/postgresql-9.6-main.log
.sudo service postgresql restart
and it should be fine.I have searched a lot to find this, credit goes to this post.
Best of luck!
I recommend you should clarify port that postgres. In my case I didn't know which port postgres was running on.
then you can know which port is listening.
with port option, might be answer. you can use psql.
Open your database manager and execute this script
Use command: