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:36

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

Mac ports issue: https://trac.macports.org/ticket/30125

查看更多
骚的不知所云
3楼-- · 2019-01-01 06:36

Another possible solution that worked for me is resetting the postmaster file by deleting it. Simply run:

rm /usr/local/var/postgres/postmaster.pid 

It's worth checking the log for errors which you can find here:

/usr/local/var/postgres/server.log

The error message I was having was:

FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 161) running in data directory 
"/usr/local/var/postgres"?

Everything worked great afterwards.

查看更多
素衣白纱
4楼-- · 2019-01-01 06:36

I'm new to Rails, but adding the following to database.yml worked for me:

host: localhost

port: 5432

Not sure why Rails defaults to domain sockets instead of TCP, while PostgreSQL does not set up domain sockets by default.

查看更多
浪荡孟婆
5楼-- · 2019-01-01 06:37

If you like a permanent change in your $PATH try this:

defaults write $HOME/.MacOSX/environment PATH "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/opt/local/bin"

this will rewrite your ~/.MacOSX/environment.plist.

查看更多
君临天下
6楼-- · 2019-01-01 06:38

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
查看更多
几人难应
7楼-- · 2019-01-01 06:50

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.

查看更多
登录 后发表回答