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'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
Disregard the '---' signs, as they are being used there only for alignment. The important information are the version and the cluster. You can also check whether the server is running or not in the status column.
pg_ctlcluster <version> <cluster> start
, so in my case, using version 9.6 and cluster 'main', it would be pg_ctlcluster 9.6 main start
/var/log/postgresql/postgresql-<version>-main.log
, so in my case, the full command would be sudo nano /var/log/postgresql/postgresql-9.6-main.log
.2017-07-13 16:53:04 BRT [32176-1] LOG: invalid authentication method "all"
2017-07-13 16:53:04 BRT [32176-2] CONTEXT: line 90 of configuration file "/etc/postgresql/9.5/main/pg_hba.conf"
2017-07-13 16:53:04 BRT [32176-3] FATAL: could not load pg_hba.conf
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!