mayrues
mayrues

Reputation: 171

could not connect to server: "/var/run/postgresql/.s.PGSQL.5432"?

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

Upvotes: 17

Views: 36388

Answers (8)

rdaniels
rdaniels

Reputation: 979

Review the postgresql.log file

Mine said FATAL: lock file "postmaster.pid" already exists So I removed the postmaster.pid file and restarted the service, now it's working

λ /usr/local/var/postgres/ rm postmaster.pid
λ /usr/local/var/postgres/ brew services restart postgresql  

Upvotes: 0

Prateek Arora
Prateek Arora

Reputation: 666

Try this that works for me.

sudo systemctl start postgresql

then

sudo systemctl start postgresql

Upvotes: 0

Shiva
Shiva

Reputation: 12514

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.

Upvotes: 2

Sanjay Choudhary
Sanjay Choudhary

Reputation: 222

sudo systemctl start postgresql

Upvotes: 0

ToTenMilan
ToTenMilan

Reputation: 640

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

Upvotes: 0

Sergey Bezugliy
Sergey Bezugliy

Reputation: 672

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

sudo service postgresql stop --force

sudo service postgresql start --force

Upvotes: 2

apeironsv22
apeironsv22

Reputation: 1

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.

Upvotes: -1

ramamoorthy_villi
ramamoorthy_villi

Reputation: 2055

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

Upvotes: 3

Related Questions