问题
I recently had major permission problems using Lion Server where permissions would change on folders at will. During this time I had started getting the following error when trying to do a rake db:migrate command:
rake aborted!
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
This had been working before when I first created a Rails 3.2.3 application while running 10.7.2. All of a sudden I started having this error come up. I read many blogs about this error and tried to remove it but with no success.
I decided to call Apple Enterprise Support to see what I could do. I suspected that Lion Server had gotten corrupted but wanted to confirm with the support team before wiping my server clean and starting over. They confirmed that is what I needed to do in order to straighten it out. I did this on Friday and only installed what I needed to rebuild my Rails app. I still got the error. I tried again some of the other solutions that were posted but still none of them worked. We continued to look for solutions.
回答1:
After continuing to search for blog posts we were able to find one that dealt with Lion 10.7.4. What I did not know that something had changed between 10.7.2 when I started writing my Rails application and now with PostgreSQL. We found the following blog post which helped me solve the problem I had for several days.
http://www.mactasia.co.uk/revisited-using-postgresql-in-lion-server
I ended up logging in as root and doing the following:
Made the following changes in /System/Library/LaunchDaemons/org.postgresql.postgres.plist
listen_addresses=127.0.0.1
unix_socket_permissions=0777
Changed the permissions of /var/psql_socket
sudo chmod 755 /private/var/pgsql_socket
Afterwards I logged out of root and logged in as I normally do as a server admin. I no longer got the permission error.
回答2:
which psql
will most likely show /bin/psql
I'm guessing we want to call /usr/local/bin/psql
So either we change the $PATH to include /local/bin prior to /bin, which I don't think is a very good solution (security and such), or We remove /usr/bin/psql by either rm-ing (or mv-ing) the file, (and symlinking to /usr/local/bin) or uninstalling the psql client.
来源:https://stackoverflow.com/questions/11377416/postgresql-permission-denied-error-on-unix-domain-socket-var-pgsql-socket-s-p