DEV Community

Venkatesh.pala
Venkatesh.pala

Posted on

Postgres13 reset lost password Mac BigSur

Lost your password for the Postgres server?
You can do the below for development, it lets you develop without a password. This below is a quick fix I used for my development purposes. I assume you've knowledge of Vim and Postgres. You can stop at step 9 if you want to leave a blank password. But if you want to reset your password follow the rest.
To reset the password you need to edit the "pg_hba.conf file"
You can locate this file in your applications else you can copy the following to your terminal "sudo vi Library/Application\ Support/Postgres/var-13/pg_hba.conf"
You need to update the "md5" method for all users to "trust" near the bottom of the file.
Locate the name of the service, from the list using the following in your terminal "ls /Library/LaunchDaemons"

  1. Find the postgresql and stop the postgresql service.
  2. Then, from the terminal "sudo launchctl stop com.edb.launchd.postgresql-13"
  3. Again, start the postgresql service. You can do from the terminal using the following "sudo launchctl start com.edb.launchd.postgresql-13"
  4. You can start psql session as postgres "psql -U postgres"
  5. Now, it will not ask for a password because of the fix in the trust setting that you've applied above.
  6. You can reset password in psql session by typing "ALTER USER postgres with password 'secure-new-password';"
  7. followed by "\q" to exit the current line in the terminal "enter"
  8. Edit the pg_hba.conf file, using "vi pg_hba.conf".
  9. Switch it back to 'md5' and restart services again.

Top comments (0)