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