Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Postgres(Windows安装)上忘记了管理员密码,可以';t重置_Windows_Postgresql_Psql - Fatal编程技术网

在Postgres(Windows安装)上忘记了管理员密码,可以';t重置

在Postgres(Windows安装)上忘记了管理员密码,可以';t重置,windows,postgresql,psql,Windows,Postgresql,Psql,我安装了Windows PostgreSQL 根据一些帖子,没有为“postgres”用户设置默认密码,但我无法使用空密码字符串连接 我尝试连接时收到此异常: Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres" 最相关的提示是: 我尝试过并重新启动了PGAdmin,但当我尝试连接时,它仍会询问我密码: Caused by: org.pos

我安装了Windows PostgreSQL

根据一些帖子,没有为“postgres”用户设置默认密码,但我无法使用空密码字符串连接

我尝试连接时收到此异常:

Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
最相关的提示是:

我尝试过并重新启动了PGAdmin,但当我尝试连接时,它仍会询问我密码:

Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"

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”的默认密码?

更新您的
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
文件中的
行主机所有0.0.0.0/0

然后,您可以在
psql
终端中使用以下命令更改postgres用户角色并将密码设置为您喜欢的任何密码

[psql] alter role postgres password <new_password>;

在这一点上,你的密码应该根据AK47的答案和一些附加信息更改为新密码,我通过以下操作修复了它

1) 停止Postgres(如果当前正在运行),命令行如下。需要给它“数据”目录。在我的例子中,C:\PostgreSQL\data

pg_ctl -D C:\PostgreSQL\data stop
2) 编辑文件
pg_hba.conf
(它也在\data目录中),如下所示:

正如AK40所写,c将所有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) 快跑

4) 在出现的PG命令提示符中

ALTER USER Postgres WITH PASSWORD '<newpassword>';

7) 以后可能想在
pg_hba.conf
中恢复
MD5->Trust
更改。我遇到了相同的问题,无法在windows计算机的CLI中使用Postgres,但我设法通过

%APPDATA%\PostgreSQL\pgpass.conf 
注意:在pgAdmin中创建服务器或数据库时,必须选择存储密码选项


我希望这有帮助。谢谢。

我在Windows上。我编辑了这个文件,但是没有“service postgresql restart”。我将根据我留下的一些细节更新我的答案。我希望能够准确地指出,所有“md5”地址都必须更改。信任每一个连接,甚至是来自服务器外部的连接都可能是危险的。如果服务器停止,您希望
psql-U postgres
如何工作?这就是服务器重新启动的原因
psql -U postgres
ALTER USER Postgres WITH PASSWORD '<newpassword>';
pg_ctl -D C:\PostgreSQL\data start
%APPDATA%\PostgreSQL\pgpass.conf