Repairing Postgresql after upgrading to OSX 10.7 L

2019-01-01 06:33发布

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!

15条回答
临风纵饮
2楼-- · 2019-01-01 06:51

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.

查看更多
只靠听说
3楼-- · 2019-01-01 06:54

My PostgreSQL is installed in /Library/PostgreSQL so that /usr/var stuff didn't work for me.

It appears that Woz is correct because everytime I close my macbook pro's lid it crashes... Here is what worked post-crash for me:

sudo su postgres -c "/Library/PostgreSQL/9.2/bin/pg_ctl -m fast -D /Library/PostgreSQL/9.2/data restart"
查看更多
听够珍惜
4楼-- · 2019-01-01 06:56

You may need to specify the host of your database.

查看更多
看淡一切
5楼-- · 2019-01-01 06:57

I ran into this as well, but I had installed postgres myself (not with homebrew). If that's the case, you need to find the old path to psql (which may be /usr/local/bin, but for me was /usr/local/pgsql/bin) and prepend that to your $PATH.

(before) which psql => /usr/bin/psql

(fix) export PATH=/usr/local/psql/bin:$PATH

(after) `which psql' => /usr/local/psql/bin

John Wang's suggestion to source ~/.bash_rc afterward you add that to your bash_rc is golden.

查看更多
深知你不懂我心
6楼-- · 2019-01-01 06:59

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.

查看更多
零度萤火
7楼-- · 2019-01-01 06:59

I had the same issue and was having problems making John Wang's solution work. As Darren noted there's an issue with the pg gem. To get it work I needed to:

gem uninstall pg

Then reinstall.

Which got it working.

查看更多
登录 后发表回答