6

I am trying to get postgres setup locally for a rails app on my mac (10.7 Lion).

I installed postgresapp and launched it, I now have an elephant in my status bar telling me that postgres is running.

I can get to it by:

psql -h localhost

But when I simply run psql I get this error:

psql: 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 put this:

PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

In ~/.bashrc and opened a new terminal. But no dice.

When I run which psql I get /usr/bin/psql

Not really sure what to do.. I am still pretty new to unix systems. Should I symlink /usr/bin/psql to /Applications/Postgres.app/Contents/MacOS/bin/psql?

JD Isaacks
  • 56,088
  • 93
  • 276
  • 422
  • 1
    Where does the other `psql` come from, the one in `/usr/bin/` ? Preinstalled with Mac OS X? From a different PostgreSQL package? – Craig Ringer Aug 16 '12 at 02:58
  • @CraigRinger I would assume it was preinstalled. – JD Isaacks Aug 16 '12 at 03:14
  • Is there a psql executable in `/Applications/Postgres.app/Contents/MacOS/bin`? It should be there. What happens if you try to run that one (specifying the path)? – dezso Aug 16 '12 at 06:30
  • @dezso Yes there is an executable, if I run that one specifying that path it loads the psql console correctly. – JD Isaacks Aug 17 '12 at 03:17
  • Then I'd make an alias in the `.bashrc`. Replacing the other executable with a symlink may (or may not) break something. Regarding the order `$PATH` is processed: do you have something in `/etc/path.d` (with `/usr/bin` in it)? If yes, then possibly you can set your path there. – dezso Aug 17 '12 at 06:05
  • 1
    This is a duplicate of [this question](http://stackoverflow.com/questions/11679247/how-can-i-setup-the-path-for-heroku-postgresql-app), which has a good answer. – michael Dec 14 '12 at 20:12

2 Answers2

11

I had a similar issue on my new MacBook Pro running Mountain Lion. I downloaded the PostgresApp and when I fired up rails I received the following error:

`initialize': could not connect to server: No such file or directory (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

To fix this I had to explicitly define the host and port in my database.yml file like so:

development:
  adapter: postgresql
  encoding: unicode
  database: my_app_development
  pool: 5
  username: tony
  password: stark    
  host: localhost
  port: 5432
Michael Minton
  • 4,447
  • 2
  • 19
  • 31
3

This error is pretty specific and tells you what is wrong, but if you're new to unix then it's less obvious.

I gave a similar answer to it here:

Can not connect to local PostgreSQL

The Problem

You don't have access to the ("socket") file /var/pgsql_socket/.s.PGSQL.5432

To fix:

Check that you at least have access to the directory. On the command line use:

ls -l /var/pgsql_socket/.s.PGSQL.5432

This will result in "permission denied" if not. It's likely that you do already have access to this and it's just the socket file you don't have permission to.

The socket file itself is created by postgresql when it starts up.

Track down the main configuration file for postgres (postgresql.conf). That in itself could be difficult, I'm a linux user not OSX. You may need to spend some time on google. This link is quite old but it may put you on the right track if you're having trouble. http://www.postgresqlformac.com/server/howto_edit_postgresql_confi.html

Once you've found it, find the lines in postgresql.conf they should say something like:

unix_socket_directory = '/var/pgsql_socket'    # dont worry if yours is different
#unix_socket_group = ''                        # default is fine here
unix_socket_permissions = 0777                 # check this one
Community
  • 1
  • 1
Philip Couling
  • 13,581
  • 5
  • 53
  • 85