1

I have a VPS with Ubuntu 14.04.5 LTS (GNU/Linux 2.6.32-042stab127.2 x86_64) and also have Postgresql installed. I'm using Postgresql in a ruby on rails application. Suddenly my application stopped working throwing the error

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

    $psql -V 
     psql (PostgreSQL) 11.0 (Ubuntu 11.0-1.pgdg14.04+2)

    $pg_config --version
      PostgreSQL 11.0 (Ubuntu 11.0-1.pgdg14.04+2)

    $postgres -V
     The program 'postgres' is currently not installed. You can install it by typing:
     apt-get install postgres-xc

   $locate bin/postgres
    /usr/lib/postgresql/11/bin/postgres
    /usr/lib/postgresql/9.3/bin/postgres
    /usr/lib/postgresql/9.4/bin/postgres
    /usr/lib/postgresql/9.5/bin/postgres

  $/usr/lib/postgresql/11/bin/postgres -V
    postgres (PostgreSQL) 11.0 (Ubuntu 11.0-1.pgdg14.04+2)

  $pg_lsclusters
  9.3 main    5432 down   postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
  11  main    5433 down   postgres /var/lib/postgresql/11/main  /var/log/postgresql/postgresql-11-main.log

The postgres status is down

 $service postgresql status
 9.3/main (port 5432): down
 11/main (port 5433): down

 $systemctl status postgresql.service

  postgresql.service
  Loaded: error (Reason: No such file or directory)
 Active: inactive (dead)

 $systemctl status postgresql@9.3-main.service

   postgresql@9.3-main.service
   Loaded: error (Reason: No such file or directory)
   Active: inactive (dead)

$grep -H '^port' /etc/postgresql/*/main/postgresql.conf /etc/postgresql/11/main/postgresql.conf:port = 5433
/etc/postgresql/9.3/main/postgresql.conf:port = 5432

I am trying to start Postgresql 9.3 with

 $service postgresql start 9.3
    * Starting PostgreSQL 9.3 database server                                                                                          
    * Failed to issue method call: Unit postgresql@9.3-main.service failed 
     to load: No such file or directory. See system logs and 'systemctl 
     status postgresql@9.3-main.service' for details.


  $sudo systemctl start postgresql
   Failed to issue method call: Unit postgresql.service failed to load: No 
   such file or directory. See system logs and 'systemctl status 
    postgresql.service' for details.


   $/etc/init.d# /etc/init.d/postgresql start
    * Starting PostgreSQL 11 database server                                                                                           
    * Failed to issue method call: Unit postgresql@11-main.service failed to 
    load: No such file or directory. See system logs and 'systemctl status 
    postgresql@11-main.service' for details.

    [fail]
   * Starting PostgreSQL 9.3 database server                                                                                          
   * Failed to issue method call: Unit postgresql@9.3-main.service failed to 
    load: No such file or directory. See system logs and 'systemctl status 
    postgresql@9.3-main.service' for details.
    [fail]

I'm unable to start PostgreSQL.I don't understand why it went down suddenly, it was working fine till yesterday.

2 Answers2

4

According to pg_lsclusters, your PostgreSQL instances 9.3/main and 11/main are not started. That explains the "could not connect to server" error.

postgresql.service and postgresql@9.3-main.service are systemd unit files and your problem seems to be that they're missing when systemctl needs them.
Note that systemctl does not get installed by default on Ubuntu 14.04, as it's the last version that doesn't use systemd (see Is Ubuntu 14.04 using systemd?) . But somehow systemd got installed on your system.

With systemd, normally the postgres service files should be automatically created by /lib/systemd/system-generators/postgresql-generator, provided by the postgresql-common package, and end up as *.service unit files in /lib/systemd/system/.

I cannot guess why that part didn't work or ceased to work on your system.

How to start PostgreSQL manually

The pg_ctlcluster command works independently of systemd or upstart. You should be able to start the PostgreSQL instances with:

$ sudo pg_ctlcluster 9.3 main start
$ sudo pg_ctlcluster 11 main start
0

In my case systemd was running on Ubuntu 14.04 but this is supported earliest from 16.04. So I ran sudo apt-get remove systemdIn my case systemd was running on Ubuntu 14.04 but this is supported earliest from 16.04. So I ran

sudo apt-get remove systemd

After, postgresql service has been run with success.