16

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

mayrues
  • 161
  • 1
  • 1
  • 4
  • Is your postgres server running? – andHapp Mar 31 '14 at 13:28
  • 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 Mar 31 '14 at 13:40
  • I'm using Ubuntu 13.10. I searched for the error message, but I didn't find any for resolved it. – mayrues Apr 01 '14 at 18:55
  • 1
    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 http://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge -> restart postgres and my app run in local perfectly. I am very happy¡. – mayrues Apr 04 '14 at 04:42
  • @mayrues Can you write your solution with more details? I have the same problem – nourza Apr 17 '20 at 09:31

8 Answers8

3

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

Community
  • 1
  • 1
ramamoorthy_villi
  • 1,939
  • 1
  • 17
  • 40
2

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

sudo service postgresql stop --force

sudo service postgresql start --force

Community
  • 1
  • 1
Sergey Bezugliy
  • 580
  • 7
  • 23
1

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.

Shiva
  • 11,485
  • 2
  • 67
  • 84
0

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

ToTenMilan
  • 582
  • 1
  • 9
  • 19
0
sudo systemctl start postgresql
  • Please put your answer always in context instead of just pasting code. See [here](https://stackoverflow.com/help/how-to-answer) for more details. – gehbiszumeis Feb 28 '20 at 09:29
0

Try this that works for me.

sudo systemctl start postgresql

then

sudo systemctl start postgresql

Prateek Arora
  • 616
  • 8
  • 7
0

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  
rdaniels
  • 939
  • 8
  • 7
-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.