Ubuntu – Cannot connect to PostgreSQL server

postgresql

I'm trying to set up a PostgreSQL server using the instructions found on here. I installed the package via apt-get install postgresql and now I'm on the step:

sudo -u postgres psql postgres

which gives the 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"?

I'm guessing the server isn't running but I'm not sure how to start it. Any tips would be much appreciated.

UPDATE: Running service postgresql status doesn't output anything, even after sudo service postgresql start.

UPDATE #2: Running ps auxw | grep post doesn't turn up anything either, so I'm guessing the server daemon isn't running.

Best Answer

Check what database clusters are currently created:

pg_lsclusters

If there is one, but it's not running, then start it (substituting the version and name):

sudo pg_ctlcluster x.y name start

If there isn't one, create one and have it started:

sudo pg_createcluster --start x.y name

Normally, this should have happened automatically when you install the package. So either something happened during package installation, or the package was already installed and someone had already messed around with the things I show above.

Related Question