Monday, December 2, 2013

Resetting PostgreSQL 'postgres' user password in Mac

  1. Edit the pg_hba.conf file
    1. sudo vi /Library/PostgreSQL/9.2/data/pg_hba.conf
    2. Change the "md5" method for all users to "trust" near the bottom of the file
  2. Find the name of the service
    1. ls /Library/LaunchDaemons
    2. Look for postgresql
  3. Stop the postgresql service
    1. sudo launchctl stop com.edb.launchd.postgresql-9.2
  4. Start the postgresql service
    1. sudo launchctl start com.edb.launchd.postgresql-9.2
  5. Start psql session as postgres
    1. psql -U postgres
    2. (shouldn't ask for password because of 'trust' setting)
  6. Reset password in psql session by typing
    1. ALTER USER postgres with password 'secure-new-password';
    2. \q
    3. enter
  7. Edit the pg_hba.conf file
    1. Switch it back to 'md5'
  8. Restart services again

10 comments:

Unknown said...

Very informative and well written post! Quite interesting and nice topic chosen for the post.
CyberPowerPC Laptops

Unknown said...

Nice information

Anonymous said...

This was really helpful, thanks!

Anonymous said...

Really useful, thank you for the help!!

Unknown said...

Unfit to Retrieve Postgres Password? Contact to Postgres SQL Support for Linux to settle issue
In the event that whenever you experienced this secret word related issue in your Postgres SQL at that point attempt these beneath ventures to take care of this issue: first you need to set the watchword for client Postgres, now you need to change your pg_hba.conf lastly reload the Postgres server. By attempting these means you can undoubtedly take care of your concern yet in the event that as yet having a similar watchword issue at that point contact to Postgres SQL Support for Windows or PostgreSQL Remote Database Service to get the best help.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801

Alex - Brasil said...

Really useful, thank you for the help!!

zongse said...

The only clear and working tutorial for Mac Postgres 12 on the internet. 1000 thanks!

Anonymous said...

Many thanks for working on my postgres 11, really helps !

Anonymous said...

Amazing tutorial! Still valid 7 years later on Postgres 11 and 13. Thanks very much!

Anonymous said...

The only working explanation. Step by step. Postgres 13.3