If you’ve ever found yourself locked out of your postgreSQL database, unable to recall your PostgreSQL password. Don’t worry much, we’ll walk you through the process of resetting your PostgreSQL password using the user-friendly pgAdmin4 interface.
So, let’s get on this journey together and regain access to your PostgreSQL database with ease. Ready to dive in? Let’s get started!
If you’re a visual learner , here is the full tutorial video :
Open the Postgres Installation Directory
Before doing anything else, you need to find the postgres directory and there you’ll get the configuration file . The image below shows the directory of the file that we need .
You need to copy the file that is marked in above image . Copy and paste the file in same directory for the backup purpose.
Change The Authentication Method
Now, right click on the original file i.e. pg_hba.conf and open it with notepad . Again , you need to scroll it down and change the authentication method from ‘scram-sha-256’ to ‘Trust’.
The image below shows the authentication method which is to be changed.
Once you’ve changed the authentication server, press ctrl+s
to save it.
Reset Postgres Server
After changing the authentication method , you need to restart the postgres server to solve the authentication problem.
To reset postgres server , follow the steps below:
- Open services by typing services in start menu.
- Select the postgres in services.
- Restart the service.
You can see the image below for more clarification .
After you restart postgres server, you’ll be able to login without authentication.
Change The Password
Once the server has been restarted, go to the the pgadmin4 again and cancel the password request and close it as shown in the image
Again , open the PgAdmin4 and now you’ll be able to login without password.
Once you’re logged in to PgAdmin4 , you need to change the password . To change the password follow the steps below:
- Click on the ‘ servers’ in PgAdmin4 .
Once you click on the servers you’ll see postgreSql server that means you’re connected to the server.
- Select Postgres database inside Database and click on the PSQL Tool icon.
Postgres Database
- Set The Password
Now, you can set the password in the postgres as shown in the image.
Now , the command to set password is :
ALTER USER postgres WITH PASSWORD 'Password';
Once you hit ‘Enter’ the password is set and you’ll get the message ‘ALTER ROLE’ as shown in image below:
After resetting the password , close the postgres and go the file directory of pg_hba.conf . There you need to delete the original file and rename the copied file as original file so that it asks for password again.
You can check the authentication method by right clicking the file , there you can see the same name as scram-sha-256.
Now , restart the postgres service again. Open the pgadmin4 and try new password that you set earlier. This must work now as we have done all the necessary things to reset the postgres password.
Hopefully, you’ve solved the issue regarding this and enjoyed the tutorial as we end our tutorial here.
You may also like:
Conclusion-Reset Postgres Password
In this blog post, we reset the password of postgres in pgadmin4. At first, we changed the authentication method in the postgres installation directory and we restarted the postgres service. Further, we changed the password for postgres password successfully. Following all the steps might have solved your issue. If you have any problem , let me know in the comment below.