118

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?

Jonas
  • 33,945
  • 27
  • 62
  • 64

11 Answers11

72

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

brew install postgresql@15

(you need to specify the version after @) 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 the psql command 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 it doesn't get in your PATH.

brew install libpq

So follow the instructions it says after install out to add it to your PATH, or brew link --force libpq or add a symlink.

Petrus Theron
  • 303
  • 2
  • 3
  • 9
rogerdpack
  • 1,364
  • 1
  • 15
  • 19
57

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.

Denis de Bernardy
  • 1,339
  • 1
  • 8
  • 13
20

Install just client with brew:

brew install pgcli

then link it:

brew link --force libpq

as output you will get the path to psql:

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

to find this path again:

brew info libpq
18

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.

Nick Chammas
  • 14,810
  • 17
  • 76
  • 124
Eonil
  • 487
  • 7
  • 12
5

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.

Milen A. Radev
  • 1,648
  • 14
  • 13
1
brew install libpq    
brew link --force libpq 

I followed the below walkthrough and it worked. https://blog.timescale.com/tutorials/how-to-install-psql-on-mac-ubuntu-debian-windows/

nbk
  • 8,699
  • 6
  • 14
  • 27
Abhimanyu
  • 11
  • 1
1

I installed PostgresQL with the installer from https://www.postgresql.org/download/ The psql executable was put into /Library/PostgreSQL/14/bin. I added that to my path.

user1527225
  • 151
  • 2
0

You can also use the EDB Installer, but during the installation choose to install only the Command Line Tools enter image description here

Ilya
  • 101
0

If you don't want to use brew and installing the whole server is overkill, I found that pgAdmin (the GUI app) provides you with a psql cli. Right click the database and choose PSQL Tool to open up a session.

0

Kinda similar to @inyourcorner, but i had to double-click on the database... see image: (on mac) (and thanks for leading me there!)... -Click on elephant (postgres) icon in upper toolbar -Double-click on the database to work on -Takes you to terminal with prompt to enter psql commands

How to enter psql commands on mac

Fred
  • 1
  • 1
-1

To highlight the comment: /Applications/Postgres.app/Contents/Versions/latest/bin – the folder of psql

Vyacheslav
  • 191
  • 1
  • 1
  • 4