我安装了 Windows PostgreSQL。
根据一些帖子,没有为“postgres”用户设置默认密码,但我无法使用空密码字符串进行连接。
我在尝试连接时收到此异常:
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
最相关的提示是: https://stackoverflow.com/a/25943227/1005607
Open pg_hba.conf
Change md5 -> TRUST
then restart PgAdmin.
我试过了并重新启动了 PGAdmin,但是当我尝试连接时它仍然要求我输入密码:
Windows 中的任务管理器显示一些 PostgreSQL 进程正在运行。我无法关闭它们。
我已经试过了,但失败了:
pg_ctl restart
ERROR:
pg_ctl: no database directory specified and environment variable PGDATA unset
psql.exe postgres
Password: (none)
ERROR:
psql: fe_sendauth: no password supplied
如何重置用户“postgres”的默认密码?
最佳答案
根据 AK47 的回答和一些附加信息,我通过执行以下操作修复了它,
1) 如果当前正在运行,请停止 Postgres,使用下面的命令行。需要给它“数据”目录。在我的例子中 C:\PostgreSQL\data
pg_ctl -D C:\PostgreSQL\data stop
2) 编辑文件 pg_hba.conf
(它也在\data 目录中)如下:
正如 AK40 所写,将所有 MD5 引用更改为信任,例如
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
3) 现在运行
psql -U postgres
4) 在出现的PG命令提示符中输入,
ALTER USER Postgres WITH PASSWORD '<newpassword>';
5) 通过输入 wq
enter 退出 PG 提示符来保存它
6) 现在启动 Postgres
pg_ctl -D C:\PostgreSQL\data start
7) 可能希望稍后在 pg_hba.conf
中恢复 MD5 -> Trust
更改。
关于windows - 忘记了 Postgres 的管理员密码(Windows 安装),无法重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47311101/