psql command not found
Asked Answered
G

1

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.

Goa answered 8/2, 2013 at 16:1 Comment(4)
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.Catchment
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.Catchment
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).Dislimn
This answer on a related question might be of use to you: https://mcmap.net/q/422993/-how-to-put-psql-on-the-path-when-using-postgres-app-on-os-xPomade
C
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"
Calque answered 18/9, 2022 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.