Be careful when changing authentication settings. A wrong pg_hba.conf can lock you out of the database entirely. Keep a backup of the file before editing.
Reset postgres password
How to reset a forgotten postgres superuser password
- 1
Stop the PostgreSQL service
C:\> net stop postgresql-x64-18The postgresql-x64-18 service was stopped successfully. - 2
Edit pg_hba.conf to allow trust login
Open
C:\Program Files\PostgreSQL\18\data\pg_hba.confin Notepad as Administrator. Find the IPv4 local connections line and temporarily changescram-sha-256totrust:# Before (original):host all all 127.0.0.1/32 scram-sha-256# After (temporary):host all all 127.0.0.1/32 trust - 3
Start the service and connect without password
C:\> net start postgresql-x64-18# Connect without password (trust allows this):C:\> psql -U postgrespostgres=# - 4
Set a new password
postgres=# ALTER USER postgres WITH PASSWORD 'NewSecurePassword123!';ALTER ROLEpostgres=# \q - 5
Restore pg_hba.conf and restart
Edit pg_hba.conf again and change
trustback toscram-sha-256. Then restart the service:C:\> net stop postgresql-x64-18 && net start postgresql-x64-18# Verify new password works:C:\> psql -U postgres -c "SELECT current_user;"Password for user postgres:postgres
Do not leave
trust authentication in pg_hba.conf in production. It allows anyone on localhost to connect as any user without a password. Always restore scram-sha-256 after resetting the password.Change password normally
Change the postgres password when you know the current one
-- Change your own password interactively (prompts for new password):
postgres=# \password
-- Change password via SQL:
postgres=# ALTER USER postgres WITH PASSWORD 'NewPassword';
-- Change another user password:
postgres=# ALTER USER myuser WITH PASSWORD 'UserPassword';
FAQ
Password questions
What is the default postgres password after installation?
There is no default password. The EDB installer requires you to set a password during setup. If you do not remember what you set, follow the password reset procedure above.
scram-sha-256 vs md5 — which authentication to use?
Always use
scram-sha-256. It is more secure than md5 and is the default since PostgreSQL 14. Only use md5 if you have a very old client that does not support SCRAM authentication.Can I create a PostgreSQL user without a password?
Yes:
CREATE USER myuser; creates a user with no password. They can only log in if pg_hba.conf has a trust or peer entry for them. For security, always set passwords for users that connect over TCP.