Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

could not connect to server: No such file or directory (PG::ConnectionBad)

Yesterday wasn't this error. I didn't make any changes in my application. Just went to sleep and now I get this.

Error:

home/dartnyan/.rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/
active_record/connection_adapters/
postgresql_adapter.rb:651:in `initialize': could not connect to server:
No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

database.yml

default: &default
  adapter: postgresql
  pool: 5
  imeout: 5000

development:
  adapter: postgresql
  database: shop_development
  pool: 5
  username: dartnyan
  password: kurt1245
test:
 adapter: postgresql
 encoding: unicode
 database: shop_test
 pool: 5
 username: dartnyan
 password: kurt1245
like image 469
Darth Nyan Avatar asked Sep 04 '16 10:09

Darth Nyan


4 Answers

On your terminal, please run this command

rm /usr/local/var/postgres/postmaster.pid

or if you have a specific version of postgres:

## version 11 for example
rm /usr/local/var/postgresql@11/postmaster.pid 
like image 199
Abdul Basit Avatar answered Nov 17 '22 03:11

Abdul Basit


I found that typing the following into terminal helps:

$ cd /usr/local/var/postgres/

$ rm postmaster.pid

I found this over at http://alumni.lewagon.org/questions/60

It also describes what might be happening. The file may get corrupt if Postgresql was not closed 'gracefully'. Example would be if your battery on your laptop were to die.

like image 41
T. Gerdy Avatar answered Nov 17 '22 05:11

T. Gerdy


Looks like the postgres server isn't running. Start the server by running

 sudo service postgresql start
like image 2
Arun Kumar Mohan Avatar answered Nov 17 '22 05:11

Arun Kumar Mohan


I've reinstalled PostgreSQL and now it works.

like image 1
Darth Nyan Avatar answered Nov 17 '22 05:11

Darth Nyan