PostgreSQL 密码忘了
许久不登, 倒是把默认的 postgres 用户的密码给忘了...
首先关闭 PostgreSQL.
我这是 Windows 上安装的, 所以到服务 (services.msc
) 里关闭.
然后修改配置, 把 md5
改成 trust
.
到 PostgreSQL 的安装目录下找到 pg_hba.conf
# pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
然后重启服务, 使用如下命令修改 postgres 用户的密码
D:\PostgreSQL\11\bin>psql -U postgres
psql (11.5)
输入 "help" 来获取帮助信息.
postgres=# alter user postgres with password 'your_password';
ALTER ROLE
postgres=#
记得重新关闭服务, 然后把 trust
改回 md5
后, 重启服务.
搞定. 又可以欢快的在 pgAdmin 里玩耍啦...