1

I am having an issue that has been bothering me for some time now. It is with postgres on my mac. I set a password for postgres and I can not remember it for some reason. I have looked up and attempted several different methods for trying to reset the password but none of them are working and I need it fixed as soon as possible.

Here is what my pg_hba.conf file

# TYPE  DATABASE        USER            ADDRESS                 METHOD

local   all             all                                     trust

I reset the local all all trust and then restarted my postgres server running

brew services restart postgres

and when i go to try and open postgres on my terminal I get the same password issue:

omars-MacBook-Pro:postgres omarjandali$ psql -U postgres -W  -h localhost
Password: 
psql: error: could not connect to server: FATAL:  password authentication failed for user "postgres"

or

omars-MacBook-Pro:~ omarjandali$ psql -h 127.0.0.1 -U postgres
Password for user postgres: 
psql: error: could not connect to server: FATAL:  password authentication failed for user "postgres"`
Omar_Jandali
  • 485
  • 2
  • 7
  • 18

1 Answers1

0

You only configured "local" connections which are using Unix domain sockets. But your psql command line tries to establish a TCP connection (-h ...), which is not configured in your pg_hba.conf.

You need to use host instead of localin pg_hba.conf to allow trusted, non-password connections through TCP.

But that is a really, really bad idea, because that means that as soon as your Mac is visible on the internet, everybody can connect to your Postgres instance and hack it. This isn't a theoretical threat - there have been numerous posts on this site regarding that.

If you want to allow connections without passwords, at least only allow them from "localhost", not from the outside:

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    all             all             samehost                trust
  • what command should I use to access the shell... `psql -U postgres` or `psql -h 127.0.0.1 -U postgres` – Omar_Jandali Oct 12 '20 at 07:21
  • If you use `-h 127.0.0.1` you need to adjust your pg_hba.conf as I have explained. If you leave out the `-h` you can keep the current file as that initiates a "local" connection as I have explained. –  Oct 12 '20 at 07:22
  • `omars-MacBook-Pro:postgres omarjandali$ psql -U postgres Password for user postgres: psql: error: could not connect to server: FATAL: password authentication failed for user "postgres" omars-MacBook-Pro:postgres omarjandali$ psql -h 127.0.0.1 -U postgres Password for user postgres: psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"` No matter what I run i get a password. – Omar_Jandali Oct 12 '20 at 07:24
  • This is what I have.. `host all all localhost trust host all all 127.0.0.1/32 trust host all all ::1/128 trust ` – Omar_Jandali Oct 12 '20 at 07:25