Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql cannot connect to server locally

I've just installed the postgresql 9.1 on one brand new Ubuntu 12.04 LTS server with the following command : sudo apt-get install postgresql libpq-dev The installation proceeded without errors. Basically I should be able to connect to local server, however when I tap the command psql, the following errors appears :

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've searched a lot of posts online, but cannot solve problem (very often, the mentioned directory doesn't exist on my server). Can anyone suggests some solutions ? Thanks !

like image 807
Ensom Hodder Avatar asked Jul 29 '13 20:07

Ensom Hodder


People also ask

Can't connect to Postgres server?

“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.

Can't connect to Postgres server Windows?

If the connection is still failing, then there might be a permission issue in the pg_hba. conf access configuration file. Make sure this is set up correctly to accept connections from your IP. Finally, ensure there are no firewalls or iptables on the Postgres server that are blocking connections.

Can PostgreSQL be used locally?

Postgres itself is a database “server.” There are several ways to connect to Postgres via “clients,” including GUIs, CLIs, and programming languages often via ORMs. In order to run and use Postgres on your own computer, you will need to set up both a Postgres server and a client.


1 Answers

It seems that you did not install postgresql successfully. Please follow here:

sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get -y update
sudo apt-get purge postgresql* # ending * is important
sudo apt-get install postgresql libpq-dev

It will fix your problem.

like image 87
djh Avatar answered Sep 26 '22 15:09

djh