When installing Postgres on Windows, there is some default account created for user to login. One of them is postgres, but we often don;t know what's the password for this account when we first login using this account. We need to change the password for this account. How to change it?
Step 1. Modify the pg_hba.conffile
Go to the /data/ and open the pg_hba.conf.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
For the method, the default is md5 which means it needs a password, so here we need to change the method to trust and then save it
host all all 127.0.0.1/32 trust
This means user can login without any password.
Step 2 . Login to Postgres server
Once the above is done, we can login to Postgres using psql command(Postgres client) to login:
psql -U postgres
Then we can enter the psql command line mode, now we can execute the below SQL command:
ALTER USER postgres WITH PASSWORD '';
Once the above is executed, the password is changed
Step 3. Revert the login method
Now modify the pg_hba.conf file and change the method back to md5 and save it and restart the Postgres service.
Now you can using the new password to login now.