PostgreSQL “password authentication failed”: reset the password, check pg_hba
Verify the role and password, reset it with ALTER USER, and check pg_hba.conf's auth method.
Confirm you are connecting as the right role with -U, then reset the password as a superuser: ALTER USER myuser WITH PASSWORD 'newpassword'. If it broke after a config change, check pg_hba.conf's auth method and reload.
Try these fixes in order
Connect as the intended role
Make sure the role in the error is the one you intend. Bare psql uses your OS username; pass the role explicitly.
psql -U myuser -d mydbReset the role password
Connect as a superuser (for example via the postgres OS user) and set a fresh password for the role.
sudo -u postgres psql -c "ALTER USER myuser WITH PASSWORD 'newpassword';"Inspect the pg_hba.conf method
Check which authentication method pg_hba.conf applies to your connection type and address. A scram-sha-256 entry needs a SCRAM-hashed password.
sudo -u postgres psql -c "SHOW hba_file;"Reload the configuration
After editing pg_hba.conf or changing password encryption, reload the configuration so the server picks it up without a restart.
sudo -u postgres psql -c "SELECT pg_reload_conf();"Interpret what you see
You never set a password for the role
What it suggests: Roles created without a password (or with LOGIN disabled) cannot authenticate with a password at all.
Next check: As a superuser, run ALTER USER myuser WITH PASSWORD 'newpassword'.
The password works in one place but not here
What it suggests: You may be authenticating as a different role than you think; psql defaults to your OS username.
Next check: Pass -U explicitly and check which role the password belongs to.
It broke after a server upgrade or config change
What it suggests: pg_hba.conf selects the method per connection type; a scram-sha-256 line rejects md5-hashed passwords stored before the change.
Next check: Inspect pg_hba.conf and SHOW password_encryption; as a superuser.
Why this happens
- The password is wrong, or no password was ever set for the role.
- pg_hba.conf requires a password method for that connection type and the supplied credential does not match.
Still not working?
Do not set trust authentication in pg_hba.conf to make the error go away; it disables password checks for matching connections. Fix the credential or the auth method deliberately instead.
Official sources
These steps are based on the linked documentation and general diagnostics. BugMedic has not independently tested every product and system configuration. Review commands before running them.