How to run psql on Mac OS X?

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.


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 (which is encouraged), see the directions that homebrew says after installation.


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.