App overview screenshotSQL and Database Guides
PostgresMySQLSQLite
Try our free SQL Client
Tools
Connecting to Postgres
Connecting to Drivers
Installing Postgres
Setting up Postgres
Postgres   >   
Setting up Postgres   >   
Reset Password on Mac

How to reset a Postgres 14 password on Mac

Resetting a Postgres 14 password on Mac

If you have Postgres 14 installed on your Mac, you may find that you need to change the password at some point - either for security reasons, or because you simply forgot it. In either case, you’re not locked out forever.

In this guide, we'll walk you through the step-by-step process to reset your Postgres 14 password on a MacOS system.

You can reset your Postgres 14 password by following the steps below:

Step 1

First, we’ll modify the pg_hba.conf file. This file is located in the data directory of Postgres (the folder where you installed Postgres, for example: /PostgreSQL/14/data/). Look for a file called pg_hba.conf in Finder and open it in the text editor. Or, open the command line and enter the command below:

sudo vim /Library/PostgreSQL/14/data/pg_hba.conf

After opening the pg_hba.conf file with your text editor, change the ""scram-sha-256" method for all users to "trust.” The method may also say md5 - in which case, changing it to trust is still correct. You will see the md5 or scram-sha-256 method near the bottom of the file. For more information, refer to the Postgres documentation here.

Once this is done, save the file and exit it.

Step 2

We need to restart the Postgres service. This is easy in Postgres 14. Just enter the following commands:

sudo launchctl stop com.edb.launchd.postgresql-10.plist
sudo launchctl start com.edb.launchd.postgresql-10.plist

Step 3

Next, we can now start the PSQL session by running the command below:

psql -U postgres

Starting psql session

You will not be asked for a password because we have change the md5 or scram-sha-256 setting to trust in Step 1.

Step 4

Now enter the following SQL command in the terminal to change the password:

ALTER USER postgres WITH PASSWORD 'newpassword';

Changing password

Change the newpassword argument in the above command to your desired password.

Step 5

Repeat step 1 to restore the pg_hba.conf file back to the correct state. This time, change the "trust" method for all users back to "scram-sha-256" and restart the service.

Restarting the session

Conclusion

In this tutorial, you just learned how to reset your Postgres 14 password on a Mac. If you’re interested in learning more about Postgres, you can visit the Arctype documentation and Arctype blog, which contain additional details on how to do this as well.

Get help on databases and SQL. Join our Discord community.