DEV Community

Digvijay Singh
Digvijay Singh

Posted on

How to Reset the PostgreSQL `postgres` Password (Forgot Password Fix)

For many developers working with PostgreSQL locally, forgetting the postgres user password is very common.

When trying to connect using pgAdmin or psql, you might see an error like:

connection failed: FATAL: password authentication failed for user "postgres"

This guide shows a simple method to reset the password on Windows.

1) Locate the PostgreSQL Configuration File

Navigate to the PostgreSQL data folder:

C:\Program Files\PostgreSQL\16\data

Find the file:

 pg_hba.conf
Enter fullscreen mode Exit fullscreen mode

This file controls how PostgreSQL authenticates users.

2) Open pg_hba.conf

Open the file using Notepad as Administrator.

Find these lines:

local all all scram-sha-256
host all all 127.0.0.1/32 scram-sha-256
host all all ::1/128 scram-sha-256

3) Temporarily Disable Password Authentication

Change scram-sha-256 to trust.

local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust

Save the file.

This temporarily allows login without a password.

4) Restart PostgreSQL Service

Press Windows + R

Type:

services.msc
Enter fullscreen mode Exit fullscreen mode

Find the service:

 postgresql-x64-16
Enter fullscreen mode Exit fullscreen mode

Restart the service.

5) Open SQL Shell (psql)

Search for:

SQL Shell (psql)

Press Enter for all default values:

Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:

6) Reset the Password

Run the command:

ALTER USER postgres PASSWORD 'newpassword123';

Example:

ALTER USER postgres PASSWORD 'MySecurePassword';

If successful, you will see:

ALTER ROLE

7) Restore Security

Go back to pg_hba.conf and change:

trust

back to:

scram-sha-256

Restart PostgreSQL again.

8) Connect Again

Now connect using pgAdmin:

Username: postgres
Password: newpassword123
Port: 5432

The connection should work successfully.

✅ Final Notes

Use trust only temporarily

Always restore scram-sha-256

This method works for most local PostgreSQL installations on Windows

Top comments (0)