1

I'm trying to fix the problem asked / answered here:

Repairing Postgresql after upgrading to OSX 10.7 Lion

It suggests that I use export on PATH. However, here's what I'm getting:

$ which psql
/usr/bin/psql
$ export PATH=/opt/local/lib/postgresql91/bin:$PATH
$ which psql
/usr/bin/psql

...I'm sincerely confused. Why is this happening?

Community
  • 1
  • 1
varatis
  • 14,494
  • 23
  • 71
  • 114
  • 1
    `/usr/local/bin/psql` exists, right? Otherwise, you may need to run the `hash` command to update the location of a previously known executable. – chepner Jul 26 '12 at 20:42
  • @chepner Oops put the wrong `export PATH` statement up there. Path is different, problem is still the same though. – varatis Jul 26 '12 at 20:44
  • What is the export path that you are actually using? – pinerd314159 Jul 26 '12 at 20:46
  • @chepner can you explain how to use `hash`? – varatis Jul 26 '12 at 20:46
  • Try changing your PATH to get rid of /usr/bin, and make sure that bash can still find psql in /opt/local/lib/postgresql91/bin. – pinerd314159 Jul 26 '12 at 20:48
  • @pinerd314159 Code please... That's what I'm already trying to do – varatis Jul 26 '12 at 20:48
  • 2
    @varatis: For efficiency's sake, Bash will remember the location it previously found an executable on the path. You can run something like `hash -d psql` to make it forget the previously-found location of `psql`, and then the next time you try to run `psql` it will re-search `$PATH`. But I don't think that's relevant here, because `which` doesn't have access to Bash's bank of remembered locations, so it always examines `$PATH` anyway. – ruakh Jul 26 '12 at 20:50
  • @varatis: What happens if you run `/opt/local/lib/postgresql91/bin/psql`? (Maybe it doesn't exist? Maybe it doesn't have its executable bit set?) – ruakh Jul 26 '12 at 20:51
  • When you do this: export PATH=/opt/local/lib/postgresql91/bin:$PATH, you're simply adding your new path to the beginning of the $PATH variable, which is a string composed of several different paths. If you want to isolate one path, you could simply do 'export PATH=export PATH=/opt/local/lib/postgresql91/bin:' – pinerd314159 Jul 26 '12 at 20:52
  • @ruakh That's odd, it says it doesn't exist, even though I can navigate to it... – varatis Jul 26 '12 at 20:53
  • @varatis: What output do you get if you run `ls -l /opt/local/lib/postgresql91/bin/psql`? – ruakh Jul 26 '12 at 20:57
  • @ruakh no such file or directory – varatis Jul 26 '12 at 20:58
  • And if you run `ls -l /opt/local/lib/postgresql91/bin/`? – ruakh Jul 26 '12 at 21:06
  • @ruakh Same thing.... :( – varatis Jul 26 '12 at 21:08
  • @ruakh I've answered my original problem though, how to get the solution to the problem I posted above working. – varatis Jul 26 '12 at 21:08
  • @varatis: You must have a typo or something. You said you can navigate to that directory. What output do you get if you navigate there and type `pwd`? – ruakh Jul 26 '12 at 21:09
  • @ruakh Ah yeah typo... It was 90 instead of 91 – varatis Jul 26 '12 at 21:10
  • `which which`? Use `type` to examine Bash's PATH. – tripleee Jul 27 '12 at 14:52
  • Following up on @varatis's post, see http://bradconte.com/bash-path-hashing.html for an explanation of how `bash` caches executable paths. – Gili Oct 16 '12 at 18:02

1 Answers1

0

What worked the best for solving this immediate issue was using

export PATH=export PATH=/opt/local/lib/postgresql91/bin:

But please note.. this screwed up just about every other command -- it really just solved the immediate issue (that the path wasn't getting updated). I don't think this is a great long term solution, and other answers are much appreciated.

On another note, specifying the host solves the problem for the question linked to above:

psql -h localhost -U postgres

varatis
  • 14,494
  • 23
  • 71
  • 114