6

I am using Mac OS X 10.5.8. I installed Postgresql 9.1 using macports, which has installed it in /opt/local/lib/postgresql91 and created a bin folder with psql and other unix executable files.

As far as I understand that is the heart of the postgresql program (I'm saying this because other postgresql files were installed in other parts of my system and I'm not sure what those are for).

I have edited my .profile to include the path to the postgresql91/bin and ran source~/.profile.

echo $PATH

confirms the path is there. But when I type psql in the command line, I get "command not found".

I do not understand what else I should have done.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
user2054545
  • 161
  • 3
  • 9
  • 1
    This is off topic for Stack Overflow, voting to move to superuser.com . Please edit the question to include the copied and pasted output of `echo $PATH` and `ls /opt/local/lib/postgresql91/bin/`. Include the *full, exact text of the error message* too. – Craig Ringer Feb 10 '13 at 03:07
  • As for "the heart of the PostgreSQL program" - Pg is client-server. `psql` is the client. `postgres` is the server, but it's normally started up when your computer starts or manually controlled with `pg_ctl` not launched directly. The PostgreSQL tutorial will help explain much of this. – Craig Ringer Feb 10 '13 at 03:13
  • Just ran into a problem after upgrading to Postgres 12 and accepting the defaults. Postgres is moved. So I added `alias psql='/Library/PostgreSQL/12/bin/psql'` to .zshrc (or presumably add to .bash_profile). – Greg Oct 11 '19 at 01:02
  • This answer on a related question might be of use to you: https://stackoverflow.com/a/20928837/1652620 – Vincent Feb 23 '20 at 19:52

1 Answers1

0

Apple has had a couple changes of the default shell along the way. The core error presented in this question is command not found. I'll advise how to resolve that issue.

First, let's find where we have Postgresql installed:

find / -type f -name psql -print | sort

This locates all files called psql on your system. This should only report a single entry. Note there may be a lot of errors presented (e.g. find: /private/var/agentx: Permission denied). You may safely ignore those.

For your system, the binary was located here: /opt/local/lib/postgresql91/bin/psql I use homebrew, so mine is located here: /opt/homebrew/bin/psql

Take the psql off the end. That is the directory. We will use it below.

Open the Terminal.app often located in the Utilities directory of your applications.

Run this command:

open -e .profile ; open -e .cshrc ; open -e .zshrc; open -e .login; open -e .bash_profile

Ignore any errors such as:

The file /Users/risner/.zshrc does not exist.
The file /Users/risner/.login does not exist.

In the open files, you may see lines like "set path =" for .cshrc or .login and "PATH=" for others.

Add the directory path from above to all the path lines, by adding the directory path /opt/local/lib/postgresql91/bin/. For example, with .cshrc or .login where they are separated by spaces you change:

set path = ($HOME/bin /bin /sbin /usr/bin /usr/sbin /usr/X11R6/bin)

to this:

set path = ($HOME/bin /bin /sbin /usr/bin /usr/sbin /usr/X11R6/bin /opt/local/lib/postgresql91/bin)

For others where they are separated by :, change:

export PATH="~/bin:$PATH"

to

export PATH="~/bin:/opt/local/lib/postgresql91/bin:$PATH"
James Risner
  • 5,451
  • 11
  • 25
  • 47