我已经安装了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‘的默认密码?
发布于 2017-11-15 23:25:14
更新pg_hba.conf
文件以允许受信任的本地连接
[root@server] vim pg_hba.conf
>> local all all trust
然后重新启动PostgreSQL服务器
[user@machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root@server] service postgresql restart (Linux)
此时,您可以作为postgres用户使用本地连接连接到您的服务器,而无需输入密码(调用psql
命令时省略-h
参数将使用本地连接-如果您传递-h
,则这将与pg_hba.conf
文件中的host all all 0.0.0.0/0 <method>
行匹配)
[root@server] psql -U postgres
然后,您可以在psql
终端中使用以下命令更改postgres用户角色并将密码设置为您喜欢的任何密码
[psql] alter role postgres password <new_password>;
完成此操作后,您可以再次重新启动PostgreSQL服务器
[user@machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root@server] service postgresql restart (Linux)
此时,您的密码应更改为新密码
发布于 2020-05-28 20:26:04
我遇到了同样的问题,我无法在我的windows机器上的CLI中使用Postgres,但我设法追踪到了密码的存储位置
%APPDATA%\PostgreSQL\pgpass.conf
注意:在pgAdmin中创建服务器或数据库时,您必须选择了存储密码选项。
我希望这能帮到你。谢谢。
https://stackoverflow.com/questions/47311101
复制相似问题