
Contributor II
2024-01-10
03:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
PostgreSQL Password forgot
How can I recover my password for PostgreSQL 12.5?
1 Solution
Accepted Solutions

Partner - Creator
2024-01-10
06:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
G'day, Try this , let me know if it worked for you ?
Steps to Recover PostgreSQL Password
-
Access the PostgreSQL Configuration File:
- Locate the
pg_hba.conf
file in your PostgreSQL installation directory. This file controls the client authentication and is usually found in thedata
directory. - Typical path on a Unix/Linux system:
/var/lib/pgsql/data/pg_hba.conf
- Typical path on Windows:
C:\Program Files\PostgreSQL\16\data\pg_hba.conf
- Locate the
-
Edit the
pg_hba.conf
File:- Open the
pg_hba.conf
file in a text editor with administrative privileges. - Find the lines that look like this:
host all all 127.0.0.1/32 md5
orhost all all ::1/128 md5
. - Temporarily change the
md5
totrust
. This will allow you to log in without a password. - Example change:
host all all 127.0.0.1/32 trust
- Open the
-
Reload the PostgreSQL Service:
- You'll need to reload the PostgreSQL service to apply these changes.
- On Unix/Linux, you can typically do this with a command like
sudo systemctl reload postgresql
. - On Windows, restart the PostgreSQL service through the Services management console.
-
Reset the Password:
- Now, log in to the PostgreSQL command line. You can do this by running
psql -U username
whereusername
is your PostgreSQL username. - Once logged in, run the following SQL command to reset your password:
ALTER USER username PASSWORD 'newpassword';
(replaceusername
andnewpassword
with your actual username and the new password you wish to set).
- Now, log in to the PostgreSQL command line. You can do this by running
-
Restore Original Configuration:
- After resetting your password, don't forget to revert the changes made in the
pg_hba.conf
file. - Change
trust
back tomd5
or its original setting. - Reload the PostgreSQL service again as you did in step 3.
- After resetting your password, don't forget to revert the changes made in the
-
Test the New Password:
- Finally, test the new password by logging into PostgreSQL with the new credentials.
Important Notes:
- Ensure that you have the necessary administrative permissions to make these changes.
- Be cautious when editing the
pg_hba.conf
file, as incorrect settings can affect database security. - Always back up the
pg_hba.conf
file before making any changes.
60,661 Views
1 Reply

Partner - Creator
2024-01-10
06:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
G'day, Try this , let me know if it worked for you ?
Steps to Recover PostgreSQL Password
-
Access the PostgreSQL Configuration File:
- Locate the
pg_hba.conf
file in your PostgreSQL installation directory. This file controls the client authentication and is usually found in thedata
directory. - Typical path on a Unix/Linux system:
/var/lib/pgsql/data/pg_hba.conf
- Typical path on Windows:
C:\Program Files\PostgreSQL\16\data\pg_hba.conf
- Locate the
-
Edit the
pg_hba.conf
File:- Open the
pg_hba.conf
file in a text editor with administrative privileges. - Find the lines that look like this:
host all all 127.0.0.1/32 md5
orhost all all ::1/128 md5
. - Temporarily change the
md5
totrust
. This will allow you to log in without a password. - Example change:
host all all 127.0.0.1/32 trust
- Open the
-
Reload the PostgreSQL Service:
- You'll need to reload the PostgreSQL service to apply these changes.
- On Unix/Linux, you can typically do this with a command like
sudo systemctl reload postgresql
. - On Windows, restart the PostgreSQL service through the Services management console.
-
Reset the Password:
- Now, log in to the PostgreSQL command line. You can do this by running
psql -U username
whereusername
is your PostgreSQL username. - Once logged in, run the following SQL command to reset your password:
ALTER USER username PASSWORD 'newpassword';
(replaceusername
andnewpassword
with your actual username and the new password you wish to set).
- Now, log in to the PostgreSQL command line. You can do this by running
-
Restore Original Configuration:
- After resetting your password, don't forget to revert the changes made in the
pg_hba.conf
file. - Change
trust
back tomd5
or its original setting. - Reload the PostgreSQL service again as you did in step 3.
- After resetting your password, don't forget to revert the changes made in the
-
Test the New Password:
- Finally, test the new password by logging into PostgreSQL with the new credentials.
Important Notes:
- Ensure that you have the necessary administrative permissions to make these changes.
- Be cautious when editing the
pg_hba.conf
file, as incorrect settings can affect database security. - Always back up the
pg_hba.conf
file before making any changes.
60,662 Views
