9

I'm trying to install the Posgtres command-line client (typically psql on Linux). I've got postgres installed through MacPorts (postgresql90 and postgresql90-server) but still don't see the client installed.

I have searched MacPorts and am unable to find either the path to the client or a separate port to install it independently.

How can I install the psql command line client?

1

3 Answers 3

13

Macports packages several versions of PosgreSQL where each version's packages' names contain the version string. So if XY is the concatenation of major and minor PostgreSQL release version (from 8.1 through 9.4 beta as of this writing), the packages are named like this:

  • postgresqlXY (This installs the client, 'psql'.)
  • postgresqlXY-server (This is the server portion.)
  • postgresqlXY-doc (And so on.)

You simply need to activate the installed version of your choice. If you install the package "postgresqlXY" (any version), you also get the package "postgresql_select" as a dependency, which lets you query the active version of postgresql:

$ port select --list postgresql
    Available versions for postgresql:
    none (active)
    postgresqlXY

You can specify the active version like this:

$ port select --set postgresql postgresqlXY
Selecting 'postgresqlXY' for 'postgresql' succeeded. 'postgresqlXY' is now active.

That causes Macports to place a symlink from /opt/local/bin/psql (which is on the path because you installed Macports) to the binary installed at /opt/local/lib/postgresqlXY/bin/psql (which isn't on the path):

$ which psql # That created this symlink to the active version:
/opt/local/bin/psql

Note that you can always access version X.Y of the client binary via /opt/local/bin/psqlXY, which is another symlink Macports maintains for each installed version no matter what is or isn't selected. It was there before you selected version XY, and likewise remains if you select "none" to remove the standard binary name from your path:

$ port select postgresql none
Selecting 'none' for 'postgresql' succeeded. 'none' is now active.
$ which psql   # Not on the path because 'none' is active!
$ which psqlXY # But this is always present:
/opt/local/bin/psqlXY

People end up needing ready access to multiple versions of various pieces of software, and Macports makes that easy by packaging multiple versions of about 50 popular examples using this selection mechanism and corresponding somesoftware_select package as dependency. View the list:

$ port search _select
1
  • This is the perfect answer, Thank you
    – Alex
    Commented Aug 7, 2023 at 16:36
1

Found the answer at: http://www.istarelworkshop.com/2011/01/04/snow_leopard_development_server_postgresql

Like the general MacPorts installation, the path to PostgreSQL command-line tools is not known to the system, so I append /opt/local/lib/postgresql84/bin in /etc/paths.

It seems that MacPorts installs the executable but doesn't put it in the path.

1
0

Make sure you have installed the latest psql client (93 in my example)

sudo port install postgresql93

Then, in your ~/.bash_profile file, add

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

1
  • 1
    That's a weak solution, because you will need to hunt it down when you're upgrading. Do not mess up with your ~/.bash_profile. Run port select --list postgresql and choose one, such as sudo port select --set postgresql postgresql95. You will then find a symlink in /opt/local/bin, which will already be in your PATH.
    – Calaf
    Commented Sep 5, 2017 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .