I'm facing a problem with postgresql, when I try to execute queries with psql I'm getting this kind of 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"?

the solution I have found on the web is to change access rights for this file:

sudo chmod 777 /var/run/postgresql and to restart postgresql by this command line pg_ctl -D /home/mycomputer/var/postgres/ -l logfile restart

After I log as postgres user sudo su postgres But for now I'm getting this error message: psql: FATAL: role "postgres" does not exist

I have searched on the web and didn't find the good way to solve this.

Could someone help me on this please. thank you in advance

  • It may be helpful to indicate which Linux distro and version, as well as the version of PostgreSQL. However, it seems that your installation may be corrupted or someone removed the postgres role/user from the database. Also useful would be the contents of pg_hba.conf, postgresql.conf, and pg_ident.conf (they should be in /home/mycomputer/var/postgres/). – Deathgrip Jul 6 '17 at 18:18

your problem me be similar to a problem i had.

Can you start the postgresql service properly and actually see it running?


/etc/init.d/postgresql start


service postgresql start


nmap localhost

And see if the port is up. if not, you may need to create this directory and file and try restarting the service.

  • Please do not prefix the commands with dollar sign (unless absolutely necessary) or put them in quotes. Thank you. – Weijun Zhou Feb 2 '18 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.