Repairing Postgresql after upgrading to OSX 10.7 Lion

61,340

Solution 1

It's a PATH issue. Mac OSX Lion includes Postgresql in the system now. If you do a which psql you'll likely see usr/bin/psql instead of usr/local/bin/psql which is HomeBrew's correct one. If you run brew doctor you should get a message stating that you need to add usr/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 with source ~/.bash_profile and it should now be OK again.

Solution 2

For those of you who are interested, I pieced together the solution. All I needed was to add

host: localhost

to the database.yml for my environment and all was gravy.

Solution 3

I had this very problem with Mountain Lion but the only thing that worked for me was this fix:

Check where the actual target is:

sudo find / -name .s.PGSQL.5432

I needed to create this directory:

mkdir /var/pgsql_socket/

Then using the result from the find above create this symlink:

ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/

I suspect that for most people on Mountain Lion you can just create the dir and do the symlink and not waste time doing the find unless the symlink doesn't work.

PS - my PostgreSQL was installed through the official installer.

Solution 4

If the problem persists past changing the path (as it did for me), also try this...

gem pristine pg

It appears that the problem (partially) lies in the pg gem itself. When it builds, it figures out where the domain socket should be. If you change the location of the domain socket after the fact it doesn't seem to take effect until you rebuild the gem.

Solution 5

For those who installed direct from the official installer, just adding the host to the command works with no path changes:

psql -h localhost -U postgres
Share:
61,340
Dave G
Author by

Dave G

Updated on July 08, 2022

Comments

  • Dave G
    Dave G almost 2 years

    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!

    • Admin
      Admin almost 13 years
      This also hit someone in my office; we had a similar problem with getting the wrong binary, an additional problem with trying to connect to domain sockets in a different directory with different permissions, and it looks like the upgrade ate all the data on the local database. Fortunately this was just a development box, so it's not a huge deal, but mildly obnoxious. :)
    • owl
      owl almost 13 years
      I hit this one myself today and remembered reading your question yesterday. Good to see @John Wang has come out and explained it :)
  • pilif
    pilif almost 13 years
    be careful with this: This setting changes the access from the domain socket to a TCP connection. While it probably works, you might lose a bit of performance and usable ports on your machine which can be a problem depending on your setup. The solution provided by John is correct.
  • Greg
    Greg almost 13 years
    This fixed it. You can also edit /etc/paths and make sure /usr/local/bin is on the top
  • Troy
    Troy over 12 years
    Also, note that if you installed the pg gem BEFORE fixing your path, it will use the wrong psql. If so, uninstall the pg gem and then reinstall it (gem uninstall pg && gem install pg).
  • Antony Stubbs
    Antony Stubbs over 12 years
    Is this for homebrew? Ports seems to put it in: /opt/local/lib/postgresql91 So make sure you use export PATH=/opt/local/lib/postgresql91/bin:$PATH
  • Tom Harrison
    Tom Harrison over 12 years
    My path was reporting correctly, but Troy's solution of uninstalling the pg gem, then letting bundler reinstall did the trick for me.
  • Jamie Cook
    Jamie Cook over 12 years
    Just to clarify - it looks as if you are best to setup your path correctly, then uninstall/reinstall the pg gem
  • tmadsen
    tmadsen about 12 years
    'gem uninstall pg' (choose all versions), then 'bundle' again to install the pg version from your Gemfile worked for me.
  • Sathish
    Sathish about 12 years
    Thanks Dave G, this worked for me too. I installed 10.7.3 update and rake db:migrate complained. This fixed it.
  • Benjamin
    Benjamin almost 12 years
    This worked for me too. However i left the password and the username blank.
  • Emmanuel
    Emmanuel almost 12 years
    I have a feeling it might be it for me but can't make it work. I'm getting this : ln: /var/pgsql_socket/: No such file or directory
  • Space
    Space almost 12 years
    Sorry, I forgot that I ran into that too. Added extra step to answer.
  • duma
    duma almost 12 years
    Troy's comment worked for me. Running Mountain Lion, and had just installed homebrew's postgres.
  • duma
    duma almost 12 years
    I'd imagine this would work because it forces a TCP/IP connection.
  • Elliot Winkler
    Elliot Winkler over 11 years
    This worked for me, even after I fixed the PATH and reinstalled the pg gem without pristine.
  • kirpit
    kirpit over 11 years
    Also note for the Python users; you have to reinstall your PostgreSQL driver (that is likely to be psycopg2) after you fix your path issue explained above. To do that: pip uninstall psycopg2 && pip install psycopg2 within your virtualenv.
  • Dustin
    Dustin about 11 years
    I had to run this twice...odd. I did uninstall pg then bundle install and it failed. Then just did gem install pg and it worked. Thanks!
  • joncodo
    joncodo about 11 years
    uninstall pg gem? I have installed rubymine and postgres and induction. This error comes up when trying to connect to postgres through induction. How can I uninstall pg gem?
  • Michael A.
    Michael A. almost 11 years
    I had the issue only from the command line. Removing the file /usr/local/var/postgres/postmaster.pid solved my issue.
  • bhinks
    bhinks almost 11 years
    Thanks for this tip, Darren
  • Matt
    Matt almost 11 years
    Bless you Ben. Greatly appreciated.