0
votes

I've been using pgAdmin with PostgreSQL just fine but I wanted to get some practice using the command line. When I installed PostgreSQL, I made sure to include Command Line Tools. I downloaded it directly from Postgres' website - I did not use Homebrew.

From Terminal, I tried connecting using psql but it didn't work. So, I tried to see if I had set the path correctly as mentioned here: https://dba.stackexchange.com/questions/93369/postgres-installation-on-macosx-problem-with-psql

I used mdfind psql to find the path: PATH="/Library/PostgreSQL/13/bin:${PATH}"

I reloaded the .zprofile, entered psql and my password for my current user (I also tried the PostgreSQL password) but I got the following error:

psql: error: could not connect to server: FATAL: password authentication failed for user "me"

I also tried changing users to "postgres" via: sudo su - postgres and entered in the same passwords that I previously tried but it keeps saying "Sorry, try again" and then exits after 3 attempts.

pgAdmin4 is working fine, as usual. The passwords I enter into pgAdmin are the same that I tried using Terminal. Does anyone know what I am doing wrong?

Edit: 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 above.

2

2 Answers

0
votes

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

0
votes

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.