I recently upgraded to OSX 10.7, at which point my rails installation completely borked when trying to connect to the psql server. When I do it from the command line using
psql -U postgres
it works totally fine, but when I try to run the rails server or console with the same username and password, I get this error
...activerecord-3.0.9/lib/active_record/connection_adapters/postgresql_adapter.rb:950:in `initialize': could not connect to server: Permission denied (PGError)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Any ideas what might be going on would be super helpful! Thanks!
It's a PATH issue. Mac OSX Lion includes Postgresql in the system now. If you do a
which psql
you'll likely seeusr/bin/psql
instead ofusr/local/bin/psql
which is HomeBrew's correct one. If you runbrew doctor
you should get a message stating that you need to addusr/local/bin
to the head of your PATH env variable.Editing your .bash_profile or .profile, or whichever shell you're using and adding:
export PATH=/usr/local/bin:$PATH
as the first export for the
PATH
then either quit you shell session or source your file withsource ~/.bash_profile
and it should now be OK again.In my case the server didn't start because of wrong shared memory settings. At first I was confused because there were several postgres processes running, but those were standard system processes. Look for
postmaster
processes!All I needed to do was to change the shared memory settings. Fiddling around with the path settings wasn't needed in my case.
I'm not happy with the most upvoted answers as they are either OS-user specific or remap Postgres to use TCP instead of domain sockets, as pointed out by @pilif. I've seen another solution that involves re-ordering the default paths at the system level to check Brew's path before a core system path, but this seems hazardous as it could affect all other application name-collisions like this one.
This site details a solution my coworker found. It comes down to executing a single shell script that will
This comes with the caveat that the system default Postgres is whatever brew has installed, so you have to make a judgment call about whether that's right for you. I don't see myself needing Postgres 8.4 specifically over 9.x, but YMMV