0

I'm trying to setup a new app with postgresql so I can deploy with Heroku. However, when I run the app using 'rails server' my welcome to rails screen gives this error:

PG::Error

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"?

I'm sure this is the same issue as is covered here:

Repairing Postgresql after upgrading to OSX 10.7 Lion

But the fix by John Wang doesn't work.

I've tried adding 'export PATH=/usr/local/bin:$PATH' to the .bash_profile, .bashrc and .zshrc, none of which change the outcome. Calling which psql always returns /usr/bin/psql.

What am I doing wrong here? Any help would be much appreciated!

edit

Running /usr/local/bin/psql gives the same error and running echo $PATH gives:

/opt/local/bin:/opt/local/sbin:/Users/dave/.rvm/gems/ruby-1.9.3-p194/bin:/Users/dave/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/dave/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/dave/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/dave/.rvm/bin

Community
  • 1
  • 1
Dave
  • 1,175
  • 2
  • 21
  • 49

1 Answers1

2

What happens if you run your locally installed psql directly?

/usr/local/bin/psql ...

If that works then it's the path you need to change. You can just try running the export in a terminal, then which psql. If that doesn't pick up the right psql then check the export worked with

echo $PATH

I'm not sure which .xxrc file you'll need to update then - not got a mac to hand I'm afraid, but at least you'll know the command will work.

Oh - I keep several different versions of PostgreSQL around and find it useful to have some aliases set up:

alias psql90='/usr/local/pgsql90/bin/psql -p 5490'
alias psql84='/usr/local/pgsql84/bin/psql -p 5484'
alias pg_dump90=...

Your $PATH is just a list of directories to check separated by ":". It starts /opt/local/bin rather than /usr/local/bin and if you look further along you'll see /usr/bin coming before /usr/local/bin. So - we need to do two things:

  1. Find out which psql we actually want
  2. Make sure we can edit our PATH

Firstly - find your postgresql.conf file and check what port you are running on. There are three items of interest: listen_addresses, port and unix_socket_directory. Then we'll see if there's a socket there.

ls -a <your unix_socket_directory>

You should see a "file" something like ".s.PGSQL.5432" where the 5432 is the port number from your config file. If there's no such file, it's not running and it's time to get it running. You may need to change the port number in the config file if it matches Apple's existing usage.

Then find what psql installations exist

find /usr -type f -name psql
find /opt -type f -name psql

Try and figure out which one you need, perhaps add --version to help.

Then, let's see about editing your PATH. You must have some changes in your settings file anyway, so let's see if we can find where that setting is.

grep -l 'local/bin' ~/.*rc

That should list filenames containing local/bin - have a look and see if they are editing your PATH.

Richard Huxton
  • 21,516
  • 3
  • 39
  • 51
  • Thanks for the reply, I've added the output from echo $PATH it doesn't really mean much to me though, does it show a problem? – Dave Jul 05 '12 at 21:07
  • NOTE: there have been several of these issues lately, all caused by OSX having the unix-domain socket located in different directories than where they are expected (/var/ vs /tmp/ ), causing the frontend not being able to connect to the backend. – wildplasser Jul 06 '12 at 10:45