Mary Smith
Mary Smith

Reputation: 121

Ruby on Rails 4: when type rails server , got error message PG::ConnectionBad

I am new to Ruby on rails. I've created basic demo apps by tutorial learning by examples.

First it working fine, one week later i got error when type rails s,

Error

PG::ConnectionBad
could not connect to server: No such file or directory Is the server running      
locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I am using PostgreSQL database.

I am on MAC OS X 10.8.5

I have found similar questions on SO, but they are experiencing at some advance stage and thus involves some advance solutions.

when type

which psql
/usr/local/bin/psql

Upvotes: 0

Views: 448

Answers (2)

janfoeh
janfoeh

Reputation: 10328

It seems upgrading your OS has changed the permissions on the directory where Postgres keeps its data.

Run

sudo chown -R sabir:staff /usr/local/var/postgres

to make your user account the owner of that directory. Enter your password when it asks for it; you will not see the characters as you enter them.

The homebrew version of Postgres includes the ability to start automatically. To check whether your installation does, run

ls -l ~/Library/LaunchAgents/

You should see a line ending with homebrew.mxcl.postgresql.plist. If you do not see this line, run

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

in order to have it start automatically.

Finally, run

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

to make sure Postgres is active now. Confirm by typing

psql -l

Upvotes: 1

ernd enson
ernd enson

Reputation: 1764

When you install postgres using homebrew, than maybe you just started it manually in foreground. So after closing the terminal window postgres was not running anymore.

I'd suggest to do the following steps:

  • Check if postgres is running by grepping the process list: ps aux | grep postgres
  • if it's running try to sudo kill -9 {POSTGRES_PID}
  • if not running, use brew info postgres to see how to start it manually (or on startup etc.)
  • start postgres with the result from homebrew - in my case postgres -D /usr/local/var/postgres

I hope, that will help you out. If you installed postgres on another basis, I can change my answer accordingly.

Upvotes: 0

Related Questions