Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error with postgresql datababse : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

When I run the rake db:migrate or run the rails s command, I get the same error:

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

I get the error in the browser when I try rails s.

This is my database.yml

default: &default
adapter: postgresql
encoding: unicode

pool: 5

development:
<<: *default
database: books_development




test:
<<: *default
database: books_test



production:
<<: *default
database: books_production
username: abd
password: <%= ENV['BOOKS_DATABASE_PASSWORD'] %>

Note : I have the databases books_development; books_test ; and the postresql are running without problems when I try sudo /etc/init.d/postgresql start

I did run:

create database books_development;
create database books_test; 

in the psql console. And it said that it's done successfully

I tried a lot of solutions and I spent yesterday looking for a solution and no solution in the related questions solved my error.

I have postgresql-9.4 (the latest) and xubuntu 14.04

Any Ideas?

like image 950
adyouri Avatar asked Mar 08 '15 11:03

adyouri


People also ask

How do I connect to Postgres port 5432?

You can use psql -U postgres -h localhost to force the connection to happen over TCP instead of UNIX domain sockets; your netstat output shows that the PostgreSQL server is listening on localhost's port 5432.

Is Postgres running on port 5432?

The PostgreSQL database service is available on localhost and the default PostgreSQL port is 5432 .

How can I tell if Postgres is running on 5432?

Usually Postgres is the only app interested in using port 5432, but if after issuing the first command to see what is running on port 5432, you find out that there is an application other than PostgreSQL running on port 5432, try to check the activity monitor and see what app might be interfering with your PostgreSQL ...


1 Answers

The convention for PostgreSQL packaged for Debian or Debian derivatives such as Ubuntu is to use /var/run/postgresql as the directory for Unix domain sockets. On the other hand the convention for self-compiled postgres client libs is to use /tmp, unless self-configured otherwise.

So the usual root cause of this mismatch between both is a mix of self-compiled client-side stuff with pre-compiled server-side packages (even if client and server are installed on the same machine, client-side and server-side are still distinct and can be out of sync).

Soft-linking from /tmp to this directory as suggested by the asker works except that the link will be lost at every reboot, because in general /tmp is emptied on reboot.

A better option would be to add as an entry in database.yml:

  • either host: /tmp if the real socket path is /tmp (self-compiled server, packaged client)

  • or host: /var/run/postgresql if the real socket path /var/run/postgresql/ (packaged server, self-compiled client).

When the value in the host field starts with a slash character, the postgres library knows that it's the location of a directory for local sockets rather than a hostname. The filename inside the directory .s.PGSQL.portnumber is generated and must not be specified, only the directory.

Another possibility is to configure the self-compiled software packages as closely as possible to Debian, overriding the defaults as they do.

like image 155
Daniel Vérité Avatar answered Sep 21 '22 13:09

Daniel Vérité