Actually, I installed PostgreSQL 9.4 (with postGIS extension), and when installed, everything used to work fine.

As said on many tuts, I've set the /data folder, checked configuration files, and so on. Worked on other projects so I did not work on psql for a while But when installation was done, it used to work correctly, I made a test database, initialized postgres user, etc.

Now, I try to start psql (with "default" postgres user) and cannot connect! Start/stop/restart service do not change anything...

Result of "psql" command (with postgres user) :

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"?

When I check service status, I get this :

postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled)
Active: active (exited) since tue 2016-05-24 09:24:13 CEST; 3s ago
Process: 5658 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 5658 (code=exited, status=0/SUCCESS)

Starting/Stopping/Restarting service with command

sudo service postgresql start (or restart or stop)

Does not change anything to actual system behaviour..

Log says:

DETAIL:  Permissions should be u=rwx (0700).
FATAL:  data directory "/var/lib/postgresql/9.4/main" has group or world access

On a debian system, postgresql files and directories should be owned by user postgres, in group postgres, with permissions of either 0700 (directories) or 0600 (files).

If they're not that, you can repair perms & ownership with:

sudo chown -R postgres:postgres /var/lib/postgresql/9.4/
sudo chmod -R u=rwX,go= /var/lib/postgresql/9.4/

Note the capital X in the chmod command. Unlike a lowercase x, that will set the execute bit only on directories and on files that are already executable (there shouldn't be any of those in the pg directories).

and then restart the postgresql service.

  • 1
    And then restart the service command using sudo service postgresql restart – Jay Modi Nov 13 '19 at 6:17
  • Also if restarting service doesn't solve the problem for some, sudo reboot – Jay Modi Nov 13 '19 at 6:27

If you are sure your postgres server is running then try to login by specifying the host as localhost. When you say psql on its own it is attempting to use a socket to connect.

I had this issue when I upgraded Postgres and wanted to still access my old server. The new psql got confused.


psql -U username -h localhost

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