How to
How to Reset Forgotten Postgres Password
Remembering a password may be a hectic task for most of us. Most of the time a situation arises to reset the password because of forgetting it. It also applies to Postgres when you forgot the current password. Postgres is basically a relational Database management system that is a freely accessible resource. Postgres originated from the University of California and it is mainly used by web, mobile, geospatial, and analytics applications as a data storage service. Since Postgres utilizes the pg_hba.conf
file in the data directory for user authentication, you need to modify it to reset the password.
Steps to Reset Postgres Password
[1] Initially, your Postgres file pg_hba.conf
needs to be backed up. Hence copy it to another location or rename it to pg_hba.conf.bk
.
[2] Change all your local connections from md5 to trust to change the pg_dba.conf
file.
[3] Now, you will be able to log in to the PostgreSQL database server without providing any password.
[4] Restart the PostgreSQL server on your Windows from Services or enter the following command
pg_ctl -D "C:\Program Files\PostgreSQL\12\data" restart
[5] Finally, use tools such as psql or pgAdmin to connect to the PostgreSQL database server.
[6] Now, use the below command to set a new password for the Postgres user.
ALTER USER postgres WITH PASSWORD 'new_password';
[6] Reload the pg_dba.conf file and restart the PostgreSQL database server. Now, connect to the PostgreSQL database server with your new password.
Related Articles:
- How to create an Apple Developer account
- How to reset forgotten Apple Watch passcode
- How to reset the password on Truth Social
- How to reset a forgotten Discord password
FAQ
Initially, a Postgres user does not require a password for authentication. However, if you need to add a password for login, connect as a Postgres user and head over to the changing password section.
Tools such as psql or pgAdmin are used to connect to the PostgreSQL database server while resetting the Postgres password.