I install postgres with homebrew and verify the postgres server is running:
brew install postgresql@14
brew services restart postgresql@14
psql --version
-> psql (PostgreSQL) 14.18 (Homebrew)
I try to connect to postgres via psql
and it expects a password. I read online that it shouldn't need a password, so I just press enter. This doesn't work:
<MYUSER>@Mac postgresql@14 % psql
Password for user <MYUSER>:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: fe_sendauth: no password supplied
psql -U postgres
but that expects a password too which I do not know.My username does match my macOS username, so as far as I know: the peer authentication mechanism (connecting without a password) should work. I read that this setting is in the file pg_hba.conf, which on my computer is located at: /opt/homebrew/var/postgresql@14/pg_hba.conf
. As far as I can tell, all these settings are as expected so there is nothing to change:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
I'm not sure what to try next. How do I connect to the postgres server? If that requires changing the password, I'm having trouble figuring out how to do that. I do see similar questions but they are very old.
Additional details:
I finally got it working. Here are the two things I did (unsure if one, or both, were required for me):
I had previously installed `pgAdmin 4`, which might have confused things when I installed postgres with homebrew. I figured I wanted to start fresh, so I scrubbed the system for all Postgres-related files. I noticed there were a bunch of postgres files at /Library
that even root
couldn't delete. Only way to delete them was to go into recovery mode, temporarily disable System Integrity Protection, restart the computer, delete those files, then of course go back into recovery mode to re-enable System Integrity Protection.
The other thing I did was I installed Postgres 15 instead of 14 via `brew install postgresql@15` . This version is mentioned here: https://www.postgresql.org/download/macosx/. It makes me curious if perhaps version 14 is incompatible with the Nov 2024 Mac I am using.
So a combination of completely uninstalling postgres and then reinstalling a later version seems to have done the trick.