Saeed Esmaili
Saeed Esmaili

Reputation: 843

Postgres can't connect to server on ubuntu 16.04

I installed postgreSQL using this tutorial, but it can't connect to server. I use this command to login to Postgres session:

sudo -u postgres psql

But I get this 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 searched in Stackoverflow and found an answer that says I have to remove postmaster.bid file using this command:

rm /usr/local/var/postgres/postmaster.pid

But it causes an error too:

rm: cannot remove '/usr/local/var/postgres/postmaster.pid': No such file or directory

These are the local directory's contents:

bin  etc  games  include  lib  man  n  sbin  share  src

So, how can I find the postmaster.bid file and remove it? (If it's the solution)

My OS is Ubuntu 16.04 .

Upvotes: 0

Views: 1595

Answers (2)

Adrian Francis
Adrian Francis

Reputation: 11

I faced this same issue on Ubuntu 18.04 and couldn't find a comprehensive answer so I did the following:

  • Uninstalled Postgresql completely :

    • sudo apt-get --purge remove postgresql-11 postgresql-client-11 postgresql-client-common postgresql-common postgresql-contrib postgresql-contrib-11
      
  • Reinstalled using the following commands:

    • sudo tee /etc/apt/sources.list.d/pgdg.list <<END
      deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
      END
      
    • wget https://www.postgresql.org/media/keys/ACCC4CF8.asc
      
    • sudo apt-key add ACCC4CF8.asc
      
    • sudo apt-get update
      
    • sudo apt-get install postgresql-11
      
  • Verify that postgresql is backup and running correctly:

    • sudo service postgresql status
      

Now when I run su -postgresql psql, the error is gone.

Upvotes: 1

Praveen C. Naik
Praveen C. Naik

Reputation: 7

Check if postgres is completely installed in Ubuntu. If not do it. The do this,

rm /usr/local/var/postgres/postmaster.pid

This should work. Else reinstall and try.!

Upvotes: 0

Related Questions