Friday, July 8, 2011

How to recover password in PostgreSQL ?


  1. If password is not provided for the super user while installing postgresql, it can be changed by following steps:
  • Open pg_hba.conf, change authentication method to trust.
  • Restart Database Server
  • Login into psql. (# psql -d <database name> -U <super user>
  • Inside psql prompt,
    Alter role <rolename> with password 'yourpassword';

  • Then quit. Now change trust authentication to md5 in pg_hba.conf.
  • Restart Database Server
  • Now, while log in to psql, you need to supply password while prompting.
  1. By default, authentication method of postgres is by ident_user type. Change it to md5 or trust in pg_hba.conf file. Md5 is recommended.