4

I've been using the same Postgres database in this same app for a month with no problems, and I didn't change anything in the database before this error randomly came up today. However, today Postgres randomly started throwing this error when I try to "rails s" (I get the same type of error when running createdb or createuser):

Exiting /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': could not connect to server: No such file or directory (PG::Error) Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

What's really weird is that my friend had the exact same errors yesterday (working on the same app), and it was fixed by him running 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 everything work. However, he is running OS X Lion, and I am running Snow Leopard, so that script wouldn't work for me.

Any ideas of (1) why this would randomly start happening and (2) how to fix it?

Andrew Smith
  • 63
  • 1
  • 9

5 Answers5

2

I had a similar problem today, although in my case postgres (installed via homebrew on MacOS 10.8) wasn't running but I couldn't start or restart it. It appeared that due to a crash a zombie was blocking the socket, to resolve it i did the following

lsof -i :5432

this showed the PID of the process blocking, I simply killed it with

kill -9 PID

and postgres restarted fine.

HTH

jomis
  • 557
  • 3
  • 6
1
  • Maybe something deleted /tmp/.s.PGSQL.5432 socket - a /tmp/ cleaning service for example.
  • Maybe you'll be able to connect using :host => 'localhost' as connection argument for PG::Connection.new() — it will avoid problems with locating proper path for Unix socket or file permissions problems.
  • If you do not want to use localhost (it probably is a little slower than a socket) then you can find where it is using lsof | grep PGSQL command as operating system administrator — if it is for example /var/run/postgres/.s.PGSQL.5432 — you would use :host => '/var/run/postres/'.
Tometzky
  • 22,573
  • 5
  • 59
  • 73
  • Tom, I know this is old answer but I am having the exact same problem, can you tell me how to stop the link /tmp/.s.PGSQL.5432 from stop getting deleted after system reboot ? as right now I have to manually create the link through "sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432" – iCyborg Jan 21 '13 at 04:24
  • iCyborg: You cannot prevent /tmp/ from cleaning as probably it is a tmpfs (a directory in memory). You can add `ln -s ...` to `/etc/rc.d/rc.local` startup script. – Tometzky Jan 22 '13 at 17:44
0

I was getting the same error when starting rails (No such file or directory). Re-installing postgres with the PostgreSQL one-click installer and rebooting resolved the issue.

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

Dan Sandland
  • 7,095
  • 2
  • 29
  • 29
0

I had a similar error and found this answer helpfull

Repairing Postgresql after upgrading to OSX 10.7 Lion

I resolved by adding

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

to my .bash_profile

Community
  • 1
  • 1
Michael Dausmann
  • 4,202
  • 3
  • 35
  • 48
0

I faced same issue and when I checked server.log I can see it was not able to find that var/postgres folder and some of the conf files.

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

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

That worked well for me and everything back to normal.

shinesecret
  • 1,402
  • 12
  • 16