How to Reset PostgreSQL User Password Using psql & pgAdmin

If you forgot your password or your connection is failing, this guide will show you exactly how to reset your PostgreSQL password step-by-step. This method works for beginners and experienced developers alike.
Why You Need to Reset PostgreSQL Password
- Your database remains secure.
- Applications and scripts can connect without errors.
- You can recover from login failures without reinstalling PostgreSQL.
How to Reset PostgreSQL User Password Using psql
Step 2: Locate the pg_hba.conf File
PostgreSQL controls authentication through a file called pg_hba.conf. You need to find it.
Windows: C:\Program Files\PostgreSQL\{version}\data\pg_hba.conf
Note : Replace <version> with your PostgreSQL version (e.g., 14, 15, 16).
Step 3: Edit the Authentication Method
Open the file in a text editor (on Windows, use Notepad as Administrator) and scroll down to the bottom of the file you can find some connection details
Becareful and Look for lines like this
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
Change scram-sha-256 (or md5) to trust so it looks like this:
# IPv4 local connections:
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
This temporarily allows PostgreSQL to log in without a password so we can reset it.
Step 4: Restart PostgreSQL
After saving the file, you need to restart the PostgreSQL service:
Windows:
- Press Windows + R, type
services.msc, press Enter - Find PostgreSQL → Right-click → Restart
Step 5: Log in Without a Password
Open Command Prompt, Terminal, or PowerShell and run:
psql -U postgresYou should now log in without being asked for a password.
Step 6: Reset the Password
Once logged in, run this SQL command:
ALTER USER postgres WITH PASSWORD 'admin123';You should see:
ALTER ROLEThis means the password has been updated successfully.
Step 7: Restore Security
Go back to the pg_hba.conf file and change the authentication back to its original value (usually scram-sha-256 or md5).
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
Change scram-sha-256 (or md5) to trust so it looks like this:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
Save the file and restart PostgreSQL again.
Step 8: Test Your New Password
Now try logging in using pgAdmin or psql:
psql -U postgresEnter your new password. It should work without errors.
Step 9: Tips for PostgreSQL Password Management
- Use a strong, unique password for your database.
- Keep your password secure in a password manager.
- Rotate passwords regularly to improve security.
- Always back up your data before making changes.
Conclusion
Forgotten PostgreSQL passwords are frustrating, but resetting them is easy if you follow these steps. By temporarily using the trust method, you can safely reset your password and restore proper authentication afterward.
Visit For SQL Tutorials