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

running on localhost gives the same result:

psql -h localhost                                                                                                                                                    ⏎ master ✱ ◼
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?

Service status:

sudo service postgresql status                                                                                                                                       ⏎ master ✱ ◼
[sudo] password for david: 
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Sat 2015-10-10 15:48:54 IDT; 26min ago
  Process: 5470 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 5470 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/postgresql.service

Oct 10 15:48:54 david-X48-DS4 systemd[1]: Starting PostgreSQL RDBMS...
Oct 10 15:48:54 david-X48-DS4 systemd[1]: Started PostgreSQL RDBMS.
Oct 10 15:49:21 david-X48-DS4 systemd[1]: Started PostgreSQL RDBMS.
Oct 10 15:51:40 david-X48-DS4 systemd[1]: Started PostgreSQL RDBMS.
Oct 10 15:51:41 david-X48-DS4 systemd[1]: Started PostgreSQL RDBMS.

running sudo netstat -nl | grep postgres gives no result

I'm running xubuntu 15.04

what should my next troubleshooting steps be?

2
  • When I'm looking for processes I use $htop it's "an interactive process viewer for Linux." en.wikipedia.org/wiki/Htop. Standard apt-get installation.
    – Elvn
    Oct 10, 2015 at 13:23
  • ps -ef |grep postgres? What's in PostgreSQL's log files? pg_lsclusters? Oct 10, 2015 at 13:39

3 Answers 3

6

YASP (Yet Another Systemd Problem)

The systemd integration of PostgreSQL in Xenial is somewhat idiosyncratic. The postgresql service unit is just a dummy which is supposed to trigger the starting of your actual database instance(s) via service dependencies. That's why it says ExecStart=/bin/true - the unit's start command is /bin/true, ie. "do nothing, successfully".

The instances have service units of their own named postgresql@<version>-<name>. You can see those by running the command

systemctl list-dependencies postgresql

Dependencies are generated by the script /lib/systemd/system-generators/postgresql-generator for all instances whose start mode is set to auto in their respective start.conf files under /etc/postgresql.

At least that's how it is supposed to work. Every once in a while, though, these dependencies stop working. Systemd will cheerfully report Started PostgreSQL RDBMS. but in fact will have done nothing, successfully.

So your next troubleshooting steps should be:

  • Check whether your instances are listed by list-dependencies.
  • If so, debug systemd's dependency processing. (Good luck.)
  • Otherwise check your instances' start.conf files.
  • If those are correct, debug the dependency generator.
2

I have a few suggestions that may help.

When you try to connect to PostgreSQL try with: sudo -u postgres psql; your user may be different for peer authentication though; so check the pg_hba.conf to be sure; this file is in your $PGDATA directory.

Another suggestion is that you may want to check the startup log and the global syslog. The former is usually in $PGDATA as pg_startup.log and the latter is /var/log/syslog.

0

I had this same problem, but in my case, it was caused by the data drive not being remounted when the server was rebooted.

I know this is just one of many possible reasons for your issue, but thought it was worth mentioning! I mounted the drive and restarted postgresql and everything works great now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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