在Postgres上忘记了管理员密码(Windows安装),无法重置 [英] Forgot Admin Password on Postgres (Windows Installation), can't reset
问题描述
我有Windows PostgreSQL安装。
根据某些帖子,没有为 postgres用户设置默认密码,但我无法使用空密码字符串进行连接。
当我尝试连接时收到此异常:
原因:org。 postgresql.util.PSQLException:致命:用户 postgres的密码身份验证失败
最相关的技巧是此:
Windows中的任务管理器显示了一些PostgreSQL进程运行。我无法关闭它们。
我尝试了此操作,但失败了:
pg_ctl重新启动
错误:
pg_ctl:未指定数据库目录,环境变量PGDATA未设置
psql.exe postgres
密码:(无)
错误:
psql:fe_sendauth:没有提供密码
如何重置用户的默认密码'postgres'?
基于AK47的答案和一些其他信息,我通过执行以下操作将其修复,
1)如果当前正在运行,则停止Postgres,在下面的命令行中。需要为其提供数据目录。在我的情况下C:\PostgreSQL\数据
pg_ctl -DC:\PostgreSQL\data stop
2)编辑文件 pg_hba.conf
(也在\data dir)如下:
如AK40所写,c 将所有MD5引用都挂在信任上,例如
#类型数据库用户地址方法
#IPv4本地连接:
托管所有127.0.0.1/32信任
#IPv6本地连接:
全部托管所有::: / 128信任
#允许具有
#复制特权的用户从本地主机进行复制连接。
主机复制全部127.0.0.1/32信任
主机复制全部:: 1/128信任
3)现在运行
psql -U postgres
4)在出现的PG命令提示符下,
使用密码'< newpassword>'更改用户Postgres;
5)输入 wq
保存退出PG提示
6)现在启动Postgres
pg_ctl -DC:\PostgreSQL\数据开始
7)可能想还原 MD5->稍后在
。 pg_hba.conf
中更改信任
I have a Windows PostgreSQL installation.
According to some posts, there is no default password set for the 'postgres' user yet I can't connect using an empty password string.
I'm receiving this exception when I try to connect:
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
The most relevant tip was this: https://stackoverflow.com/a/25943227/1005607
Open pg_hba.conf
Change md5 -> TRUST
then restart PgAdmin.
I tried that and restarted PGAdmin but it still asks me for the password when I try to connect:
The task manager in Windows shows some PostgreSQL processes are running. I can't switch them off.
I have tried this and it failed:
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
How can I reset the default password for user 'postgres'?
Based on AK47's answer and some additional info I fixed it by doing the following,
1) Stop Postgres if currently running, command line below. Need to give it the 'data' dir. In my case C:\PostgreSQL\data
pg_ctl -D C:\PostgreSQL\data stop
2) Edit the file pg_hba.conf
(it's also in the \data dir) as follows:
As AK40 wrote, change all MD5 references to trust , e.g.
# 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) Now run
psql -U postgres
4) In the PG Command Prompt that appears type,
ALTER USER Postgres WITH PASSWORD '<newpassword>';
5) Save this by typing wq
enter to exit the PG Prompt
6) Now start Postgres
pg_ctl -D C:\PostgreSQL\data start
7) Might want to revert the MD5 -> Trust
change later in the pg_hba.conf
.
这篇关于在Postgres上忘记了管理员密码(Windows安装),无法重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!