Psql could not connect to server: No such file or directory, 5432 error?
Table of Contents
Psql could not connect to server: No such file or directory, 5432 error?
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:
- Certify that postgresql service is running, using
sudo service postgresql start
- Run
pg_lsclusters
from your terminal - Check what is the cluster you are running, the output should be something like:Version – Cluster Port Status Owner Data directory9.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. - Copy the info from the version and the cluster, and use like so:
pg_ctlcluster <version> <cluster> start
, so in my case, using version 9.6 and cluster ‘main’, it would bepg_ctlcluster 9.6 main start
- If something is wrong, then postgresql will generate a log, that can be accessed on
/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
. - The output should show what is the error.
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
- Fix the errors and restart postgresql service through
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!
Psql could not connect to server: No such file or directory, 5432 error?
I had the same issue but non of the answers here helped.
How I fixed it (mac)
- Try to start postgresql with
pg_ctl -D /usr/local/var/postgres start
- Look for the Error Message that says something like
FATAL: could not open directory "pg_tblspc": No such file or directory
. - Create that missing directory
mkdir /usr/local/var/postgres/pg_tblspc
- Repeat from step one until you created all missing directories
- When done and then trying to start postgresql again it might say
FATAL: lock file "postmaster.pid" already exists
- Delete postmaster.pid:
rm /usr/local/var/postgres/postmaster.pid
- Start postgres with:
pg_ctl -D /usr/local/var/postgres start
- Done ✨
Psql could not connect to server: No such file or directory, 5432 error?
These two steps solved it for me on Mac:
rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql
EDIT:
In case you face this issue (reported by @luckyguy73): psql: FATAL: database "postgresql" does not exist
You can run
brew postgresql-upgrade-database
to fix it.