postgresqlmacoshomebrew

Downloaded postgres fresh with Homebrew on Mac but cannot connect


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

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:


Solution

  • I finally got it working. Here are the two things I did (unsure if one, or both, were required for me):

    So a combination of completely uninstalling postgres and then reinstalling a later version seems to have done the trick.