Postgresql – psql: Could not connnect to the server: No such file or directory

postgresqlpsqlUbuntu

I know that this is a question that has been posted repeatedly, but I have not been able to find an answer that suits me.

PostgreSQL 9.5 was running fine, someone decided we needed to edit the pg_hba.conf file and restart the service, so we did. From then on, this ominous error message comes up when trying to connect to the databases (we tried to revert the changes and restart the service, but this did not solve it). It looks like the process is running since

service --status-all

Shows that postgres is running, as in [ + ] postgresql

But, if I run

service postgres status

The output looks like this (the black dot at the begining is actually green):

● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2016-11-04 11:49:18 UTC; 27min ago
Main PID: 1079 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
  CPU: 0
CGroup: /system.slice/postgresql.service

Nov 04 11:49:18 kissdb systemd[1]: Starting PostgreSQL RDBMS...
Nov 04 11:49:18 kissdb systemd[1]: Started PostgreSQL RDBMS.

However, when I try to look for the PID of the process in ps output… it is not to be found, so my best guess is that something is telling the service is running while not actually being running and I don't know how to get my hands around this.

Also, I don't seem to have access to the pg_ctl, postgres commands, and there is no /var/ directory in /usr/local/, which I guess that should be worrying since almost every given answer I have looked into mentioned it.

Please, somebody help me 🙁
I can give whatever more information you may need, I don't really know what is going anymore so I don't know for sure that I have given the necessary information for someone to know what the problem is.

Best Answer

Alright, I found what was wrong with all of this.

First, by running /usr/bin/pg_lsclusters I could see that the cluster was indeed not online. Then I checked the /var/log/postgresql/postgresql-9.5-main.log file to look up what was the specific error that had caused the cluster to not be brought up and there I could see that my ph_hba.conf file was, somehow, impossible to read.

I don't know how or when the permissions changed but they did. I chmod 644them and now everything is awesome.