6

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
8

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

I had this issue after accidentally changing the permission/ownership rights. I've been able to revert things by issuing the following commands:

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

and then reloading the service

sudo service postgresql restart
0

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.

Try:

psql -U username -h localhost
-1

After doing all the steps I am still getting bellow error.

root@cloud:~# psql -U postgres -h localhost

psql: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432


root@cloud:~# systemctl status postgresql 
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: enabled)
   Active: active (exited) since Wed 2018-03-21 15:37:35 IST; 52min ago
  Process: 12215 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 12215 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/postgresql.service

Mar 21 15:37:35 kencloud systemd[1]: Starting PostgreSQL RDBMS...
Mar 21 15:37:35 kencloud systemd[1]: Started PostgreSQL RDBMS.

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.