简体   繁体   中英

Password Error when logging into POSTGRES on my MAC

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"`

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 local in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM