53

I installed PostgreSQL on a computer with Mac OS X using the One click installer. Then I try to access PostgreSQL using the psql command, but it doesn't seem to be available.

I get this message:

psql
-bash: psql: command not found

Do I have to install something more? Or how can I configure PostgreSQL so I can use it on my computer?

40

Locate the psql binary. (In a terminal, run locate psql | grep /bin, and make note of the path. (In my case, it's /opt/local/lib/postgresql90/bin/, as it was installed using MacPorts.)

Then, edit the .bash_profile file in your home folder (e.g. mate -w ~/.bash_profile assuming you've textmate), and add the needed line so it's in your path, e.g.:

export PATH=/opt/local/lib/postgresql90/bin/:$PATH

After having saved the file, read the file (. ~/.bash_profile) or open a new terminal, and type psql.

  • 18
    Thanks, my path to psql was /Library/PostgreSQL/9.0/bin/psql and I created a .bash_profile file as you suggested and it works great. – Jonas May 28 '11 at 17:18
  • 1
    @Jonas: +1 Your comment should really go into a separate answer and should be the accepted answer, because this is the default location when installing Postgres on a Mac! – Stefan Haberl Nov 20 '14 at 10:01
  • The locate command didn't work initially for me, I had to first run sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist then wait for the find process to finish – magritte May 28 '17 at 17:10
  • also had to create the .bash_profile file, mac noob here! ;-) working now though, thanks! – magritte May 28 '17 at 17:23
  • 2
    better export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin/:$PATH – andilabs Sep 22 '17 at 7:43
11

I strongly recommend using Postgres.app from the Heroku team, which is also supported by them!

It has a menubar icon and the menu has a psql item:

Postgres.app menubar icon menu

You will also find psql included here if you want the same version of that as the server (path may vary by version):

/Applications/Postgres.app/Contents/MacOS/bin

If you want, you can add this path to your startup script to execute psql directly:

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

CAVEAT! AFAIK, Postgres.app doesn't support connections via Unix sockets (I am not sure what this is...), and supports only TCP/IP connections. So don't panic if you fail to connect there from some other programs.

  • 4
    The latest documentation postgresapp.com/documentation/cli-tools.html lists the path as /Applications/Postgres.app/Contents/Versions/latest/bin – Bryan Ash Jan 18 '16 at 23:36
  • Actually comment turns out to be a better answer :) – mythicalcoder May 4 '17 at 4:43
  • better export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin/:$PATH – andilabs Sep 22 '17 at 7:43
  • I looked but couldn't find any relation between Heroku team and the app. Can you share how are they connected? – Roee Gavirel Feb 14 '18 at 13:58
11

Appears "the way" to install the client, if you want to use hombrew, is:

$ brew install postgresql

then psql (the client command line) will now be available to you (it also installs a local Postgres server/database, but you don't have to use that if all you want is the client).

Apparently there's also a 'wrapper' to psql to make it more "user friendly" also available via homebrew (brew install pgcli) in case interesting.

Pgcli is a command line interface for Postgres with auto-completion and syntax highlighting.

Another option is to install the libpq homebrew package, but you have to force-link it (which is discouraged these days)

 brew link --force libpq  

or add it to your PATH, see the directions that homebrew says after installation.

  • 4
    Apparently there's no way of using psql without installing the whole database engine. I found pgcli more convenient for when for instance you want to have all your services dockerized. Way to go @rogerdpack! – Saul Martínez Dec 31 '17 at 20:10
4

According to the installation guide after the installation has finished there should be shortcuts for StackBuilder, pgAdmin3 and psql in the Application folder of Postgres:

You will also find additional shortcuts to run pgAdmin, the psql command line interface and to access the PostgreSQL documentation.

If there are such shortcuts check where the psql's one is pointing.

  • Thanks, this aslo worked. I hadn't seen that documentation, only the documentation on postgresql.org. – Jonas May 28 '11 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.