Postgres just accidentally stopped working (Rails, PGSQL.5432)

I have been using the same Postgres database in the same application for a month without any problems, and I did not change anything in the database before this error accidentally appeared today. However, today Postgres accidentally started throwing this error when I try "rails s" (I get the same type of error when running createb or createuser):

Exit /Users/Joe/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize ': failed to connect to server: No such file or directory (PG :: Error) Does the server work locally and accept connections to the Unix domain for the domains "/tmp/.s.PGSQL.5432"?

What is really strange is that yesterday my friend had the same errors (working on the same application), and he was corrected by him using the script from http://nextmarvel.net/blog/2011/09/ brew-install-postgresql-on-os-x-lion / . After running the script, he uninstalled and reinstalled the PG gem to make it work. However, it works with OS X Lion, and I run Snow Leopard, so the script will not work for me.

Any ideas (1) why this will accidentally start happening and (2) how to fix it?

+3
source share
5 answers

I had a similar problem today, although in my case postgres (installed via homebrew on MacOS 10.8) did not start, but I could not start or restart it. It turned out that due to the failure of the zombies block the socket, to solve it, I did the following

lsof -i :5432 

it showed the process lock PID, I just killed it with

 kill -9 PID 

and postgres rebooted.

NTN

+2
source
  • Perhaps something is deleted /tmp/.s.PGSQL.5432 socket - a /tmp/ cleanup service, for example.
  • Perhaps you can connect using :host => 'localhost' as the connection argument for PG::Connection.new() - this will avoid the problem of determining the correct path for problems with Unix sockets or file permissions.
  • If you don't want to use localhost (it's probably a bit slower than a socket), you can find where it uses the lsof | grep PGSQL lsof | grep PGSQL as the operating system administrator - if it is, for example, /var/run/postgres/.s.PGSQL.5432 - you should use :host => '/var/run/postres/' .
+1
source

I got the same error when starting rails (There is no such file or directory). Reinstalling postgres with the default installer in PostgreSQL and rebooting fix the problem.

In my case, this happened after installing Mountain Lion, which probably cleared the tmp directory.

0
source

I had a similar error and found this answer helpful

Postgresql recovery after upgrading to OSX 10.7 Lion

I decided by adding

 export PATH=/usr/local/bin:$PATH 

in my .bash_profile

0
source

I ran into the same problem, and when I checked server.log, I see that it could not find this var / postgres folder and some conf files.

I did this, however I lost my data in this case

 brew uninstall postgres brew install postgres initdb `brew --prefix`/var/postgres/data -E utf8`` 

It worked out fine for me and everything is fine.

0
source

Source: https://habr.com/ru/post/1483642/


All Articles