在网络上找了一篇文章http://www.linuxidc.com/Linux/2010-04/25232.htm,如下:

Ubuntu 9.10下PostgreSQL 8.4忘记密码的解决方法
Ubuntu 9.10下PostgreSQL 8.4忘记密码的解决方法:

1.
编辑pg_hba.conf中的
83 # IPv4 local connections:
84 host    all         all         127.0.0.1/32          trust

mickey@pentest:/etc/postgresql/8.4/main$ sudo vim pg_hba.conf
mickey@pentest:/etc/postgresql/8.4/main$ sudo /etc/init.d/postgresql-8.4 restart
* Restarting PostgreSQL 8.4 database server    

2.
mickey@pentest:~$ psql -h 127.0.0.1 -U postgres
psql (8.4.2)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type “help” for help.
postgres=# ALTER USER postgres WITH PASSWORD ‘mickey’;
ALTER ROLE
postgres=# \q

3.
将pg_hba.conf中的该回
83 # IPv4 local connections:
84 host    all         all         127.0.0.1/32          md5

mickey@pentest:/etc/postgresql/8.4/main$ sudo vim pg_hba.conf
mickey@pentest:/etc/postgresql/8.4/main$ sudo /etc/init.d/postgresql-8.4 restart
* Restarting PostgreSQL 8.4 database server                                              [ OK ]

经过测试,也适用windows版本下9.1。