14
votes

I have a simple web page in Ruby On Rails with postgresql database, but when I run sever I have this error, I don't Know that I do. I use postgresql because heroku need that the aplication is in postgresql.

I work in ubuntu 13.10

The error is:

PG::ConnectionBad 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 need help

thanks

7
Is your postgres server running?andHapp
Did you search for the error message? You will find a lot of information about that, specific to mac os x. Also, did you follow the instructions for postgres.app installation, assuming that's what you are using, exactly?Craig Ringer
I'm using Ubuntu 13.10. I searched for the error message, but I didn't find any for resolved it.mayrues
I found a solution -> Just create a softlink like this : ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432 -> after I have to change in the pg_hba in line peer for md5 in line local. in this link explain correctly this stackoverflow.com/questions/18664074/… -> restart postgres and my app run in local perfectly. I am very happy¡.mayrues
@mayrues Can you write your solution with more details? I have the same problemnourza

7 Answers

3
votes

Just create a softlink like this,this works for me

$ sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432

for more info

1
votes

Also you are able to force stop and then force start the server

sudo service postgresql stop --force

sudo service postgresql start --force

0
votes

I had this error due to not properly configured connection to database, and exactly because of syntax errors in setting up environment variables i.e.

MY_APP_DB= $MY_APP_DB_NAME which is wrong, instead of MY_APP_DB=$MY_APP_DB_NAME

0
votes
sudo systemctl start postgresql
0
votes

First, you need to make sure the socket file is located in /var/run/postgresql/.s.PGSQL.5432. To check that

$ cat /var/run/postgresql/.s.PGSQL.5432

if result shows something, then the problem is anything else. But, if file is not there you need to check /tmp dir (specially for OSX Homebrew users)

$ cd /tmp
$ l

total 16
drwxrwxrwt  7 root   wheel   224B Mar 11 08:03 .
drwxr-xr-x  6 root   wheel   192B Jan 23 18:35 ..
-rw-r--r--  1 root   wheel    65B Nov  7 22:59 .BBE72B41371180178E084EEAF106AED4F350939DB95D3516864A1CC62E7AE82F
srwxrwxrwx  1 shiva  wheel     0B Mar 11 08:03 .s.PGSQL.5432
-rw-------  1 shiva  wheel    57B Mar 11 08:03 .s.PGSQL.5432.lock
drwx------  3 shiva  wheel    96B Mar 10 17:11 com.apple.launchd.C1tUB2MvF8
drwxr-xr-x  2 root   wheel    64B Mar 10 17:10 powerlog

Now, there are two ways you can solve the error

Solution One

You can change the application configuration to see for sockets at /tmp/.s.PGSQL.5432

For Rails Users

# config/database.yml

default: &default
  adapter: postgresql
  pool: 5
  # port: 
  timeout: 5000
  encoding: utf8
  # min_messages: warning
  socket: /tmp/.s.PGSQL.5432

Solution Two

You can create symlinks to the expected location

$ sudo mkdir /var/pgsql_socket
$ sudo ln /tmp/.s.PGSQL.5432 /var/pgsql_socket/

Then the error should go.

Hope this helps.

0
votes

Try this that works for me.

sudo systemctl start postgresql

then

sudo systemctl start postgresql

-1
votes

What you have to do to solve the problem of s.PGSQL.5432:

First change the unix_socket_directories postgresql.conf path / tmp / by another route

and then updates the postgres and postgres load becomes, if you want you can put the path again, and with it and recharge the postgres normally.