问题
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
回答1:
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
回答2:
Also you are able to force stop and then force start the server
sudo service postgresql stop --force
sudo service postgresql start --force
回答3:
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
回答4:
sudo systemctl start postgresql
回答5:
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.
回答6:
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.
来源:https://stackoverflow.com/questions/22762635/could-not-connect-to-server-var-run-postgresql-s-pgsql-5432