So, it turns out that I just needed to write sudo su postgres without the -. I then entered my user password, wrote psql, entered the password and then I was able to interact with Postgres using the command line.
If you're having difficulty as I was, try this and set the path as I did in my original post.
Answer from IamWarmduscher on Stack OverflowSo, it turns out that I just needed to write sudo su postgres without the -. I then entered my user password, wrote psql, entered the password and then I was able to interact with Postgres using the command line.
If you're having difficulty as I was, try this and set the path as I did in my original post.
Remove your PostgreSQL installation. Download https://postgresapp.com/ (or just click https://github.com/PostgresApp/PostgresApp/releases/download/v2.4/Postgres-2.4-13.dmg )
Configure your $PATH to use the included command line tools (optional):
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
Use psql for command line in Terminal. (I used Postgres.app on macOS and it worked very well.)
Reference document: https://www.postgresql.org/docs/13/app-psql.html
postgresql - How to run psql on Mac OS X? - Database Administrators Stack Exchange
macos - Accessing postgresql server over network in Mac - Stack Overflow
How to get started local [Mac OS]
How to use PostgreSQL on Docker on Mac M1?
Videos
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.
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.