10

I just installed the heroku PSQL app (v1.0) and i'm having trouble being able to connect my rails apps using the gem pg "0.1.4". I already added the path PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" to my .profile and my .bashrc files, but nothing seems to allow me to run psql simply by calling "psql". I had success using "psql -h localhost". When i go for "psql" i get:

Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I'm using mountain lion.

Diego Gomes
  • 565
  • 6
  • 15
  • I have exactly the same problem, I've been struggling for a few hours – Emmanuel Jul 27 '12 at 12:56
  • Same problem - path isn't working. My .bashrc has the same PATH as Diego and it isn't being loaded. If I run "source .bashrc" then "which psql" it returns the correct version"/Applications/Postgres.app/Contents/MacOS/bin/psql" however if I start a new terminal window it returns this: "/usr/bin/psql" What is the deal here? the app installs properly, can be used, but won't load from PATH. – Nick Sep 10 '12 at 22:57
  • Is this the issue? http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/ – pd40 Sep 13 '12 at 01:56
  • 1
    What's the result of the commands "which psql" "ls -la ~/" and "echo $PATH" ? – Kenny Grant Sep 17 '12 at 22:26

4 Answers4

12

Still pretty sure that both of the existing answers are answering the wrong question. The author mentions right in the title that he is having trouble with PATH, not connecting to his DB or configuring rails. This is the situation I got into, and this is my solution.

After getting postgres.app running and setting PATH in my .bashrc file as directed in the postgress.app documentation - http://postgresapp.com/documentation :

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

The problem was that this path setting was not taking effect after restarting terminal.app - running which psql was returning the copy in "/usr/bin/psql", this is the copy that comes installed with Lion and Mountain Lion, not the new version installed in "/Applications/". It even says in the Postgres.app instructions "run which psql to tell that the correct version is being loaded".

Anyway - the odd thing I found was that after I ran:

source .bashrc

Then the command "which psql" would return the correct version located in /Applications/.

At this point I was stumped and had to get some extra help. The guys I tapped also thought it was quite odd too, however they quickly found out that neither the .bashrc OR the .profile files were being loaded. This is very strange, I have not seen this on any of my other macs running leopard through lion.

Now finally the solution- I am not sure this is proper, but it did permanently fix my problem. We found that their was one profile file being loaded into the terminal - the .bash_login file. In the end the solution was just to use the .bash_login to source the .bashrc file. Here is the edit to .bash_login:

source $HOME/.bashrc

And that did it.

Anyway I can't say that this is exactly the fix that diego needed / was looking for, but it is definitely the problem for me.

Nick
  • 959
  • 1
  • 9
  • 14
  • You can also just add PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" to .bash_login. – michael Dec 14 '12 at 20:27
  • 1
    or to .bash_profile, which reloads everytime you restart your console – Victor S Feb 28 '13 at 04:12
  • If you know what you're doing, simply add `/Applications/Postgres.app/Contents/MacOS/bin` to your bash path – lavoy May 07 '13 at 16:12
  • Nick in my case none of these files are being loaded when I start iTerm.app.. How can I found out what is being loaded ? – iGallina May 20 '13 at 12:58
  • The documentation is wrong. Change "Postgres.app" to "Postgres93.app" – sixty4bit Feb 22 '14 at 01:21
  • Seems that the path has changed: See http://postgresapp.com/documentation/cli-tools.html. It should be /Applications/Postgres.app/Contents/Versions/9.4/bin – dgmora Jan 13 '15 at 21:27
4

You'll need to add host:localhost to any database configuration you're using in your development environment (read development / test/ production / etc):

config/database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: my_awesome_app_development
  pool: 5
  host: localhost
  username: my_awesome_app_development
  password:

Edit: also see Repairing Postgresql after upgrading to OSX 10.7 Lion

Community
  • 1
  • 1
kelly.dunn
  • 1,546
  • 3
  • 16
  • 23
  • He is looking for help with postgres.app PATH settings, not configuring a rails app. – Nick Sep 10 '12 at 23:10
  • @Nick: no he is not. The frontend just fails to find the unix-domain postgres-socket, which acts as a *rendez-vous* point. This is an OSX-related installation problem. (there have been several of these) – wildplasser Sep 10 '12 at 23:26
  • I am getting the same error as the OP, and hardcoding the host, like in this answer, does solve my problem. On the other hand, I need a solution that doesn't require me to do that, because that's how the work development environment is setup, and so I'm looking for alternatives. I've tried setting the `PGHOST=locahost` in `.bash_profile` and I found that has worked in some cases... – Victor S Feb 28 '13 at 04:15
2

I know this is an old question but I just had the same problem. The issue is that there is a typo in the documentation. The app is Postgres93.app, not Postgres.app, so the path should have Postgres93.app:

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

It's amazing how many posts there are about this and the typo doesn't seem to have been noticed yet. Changing that was all it took to get psql and which psql to work correctly for me.

sixty4bit
  • 7,422
  • 7
  • 33
  • 57
1

Your PATH might be wrong. To find out the PATH of your psql script (on mac) open the sql shell script from your finder in Applications/Postgres installation. This will give you a hint as to where it is installed. That opened a window which told me it is located here: /Library/PostgreSQL/8.4/scripts/runpsql.sh

Then, I set the PATH variable from the terminal window by typing:
$ PATH="/Library/PostgreSQL/8.4/bin:$PATH"

user1187534
  • 789
  • 1
  • 8
  • 12