Password guide

Reset PostgreSQL password on Windows — forgot postgres password fix

Forgot the PostgreSQL postgres superuser password on Windows? This guide walks through resetting it via pg_hba.conf trust authentication without reinstalling.

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.

How to reset a forgotten postgres superuser password

  • 1

    Stop the PostgreSQL service

    cmd.exe — Administrator
    C:\> net stop postgresql-x64-18
    The 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.conf in Notepad as Administrator. Find the IPv4 local connections line and temporarily change scram-sha-256 to trust:

    pg_hba.conf — temporary change
    # 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

    cmd.exe — Administrator
    C:\> net start postgresql-x64-18
    # Connect without password (trust allows this):
    C:\> psql -U postgres
    postgres=#
  • 4

    Set a new password

    psql
    postgres=# ALTER USER postgres WITH PASSWORD 'NewSecurePassword123!';
    ALTER ROLE
    postgres=# \q
  • 5

    Restore pg_hba.conf and restart

    Edit pg_hba.conf again and change trust back to scram-sha-256. Then restart the service:

    cmd.exe — Administrator
    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 the postgres password when you know the current one

psql
-- 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';

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.

Need to configure who can connect?

Set up pg_hba.conf rules and firewall for controlled access.

Remote connections