在 Windows 7 上更改/重置 postgresql 用户密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18587710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change/reset postgresql user password on windows 7
提问by Oto Shavadze
Several days ago I install postgesql 9.2 version on my local computer. (OS windows 7)
几天前,我在本地计算机上安装了 postgesql 9.2 版本。(操作系统 Windows 7)
Now I forgot my password and I can not login in pgAdmin.
现在我忘记了密码,无法登录 pgAdmin。
How to change postgresql password on windows 7?
如何在 Windows 7 上更改 postgresql 密码?
采纳答案by Ben
Edit pg_hba.conf
to allow you to connect without a password. Then use ALTER USER to reset the password. Then change pg_hba.conf back again.
编辑pg_hba.conf
以允许您无需密码即可连接。然后使用 ALTER USER 重置密码。然后再次更改 pg_hba.conf 。
For the documentation on pg_hba.conf, see here:
有关 pg_hba.conf 的文档,请参见此处:
http://www.postgresql.org/docs/devel/static/auth-pg-hba-conf.html
http://www.postgresql.org/docs/devel/static/auth-pg-hba-conf.html
回答by Antoine Martin
In the pg_hba.conf
file, change (temporarily) all METHOD
with trust
. EG :
在pg_hba.conf
文件中,METHOD
用trust
. EG :
host all all ::1/128 trust
instead of :
代替 :
host all all ::1/128 md5
You can find where the pg_hba.conf
is located by typing in a psql command line:
您可以pg_hba.conf
通过在 psql 命令行中键入来找到它的位置:
SHOW hba_file;
回答by Hetal Rachh
Below steps helped me to reset the password-
以下步骤帮助我重置密码-
Go to
pg_hba.conf
file at path e.g.C:\Program Files\PostgreSQL\10\data
and add below line at the end,host all postgres 127.0.0.1/32 trust
Restart the PostgreSQL service from services control panel (start -> run -> services.msc)
Connect using PgAdmin or any software that you prefer and run query,
ALTER USER postgres PASSWORD 'postgres'
Remove the line that you added in step 1.
Restart PostgreSQL.
转到
pg_hba.conf
路径中的文件,例如C:\Program Files\PostgreSQL\10\data
并在末尾添加以下行,host all postgres 127.0.0.1/32 trust
从服务控制面板重启 PostgreSQL 服务(开始 -> 运行 -> services.msc)
使用 PgAdmin 或您喜欢的任何软件进行连接并运行查询,
ALTER USER postgres PASSWORD 'postgres'
删除您在步骤 1 中添加的行。
重启 PostgreSQL。
回答by Shivam_kira
Run your psql executable file and login into your database using your old password, use the following command to login:
运行您的 psql 可执行文件并使用您的旧密码登录到您的数据库,使用以下命令登录:
.\psql.exe -U postgres
Then use
然后使用
ALTER USER <user_name> WITH PASSWORD <'new_password'>
For more information refer this link : https://www.postgresql.org/docs/8.0/sql-alteruser.html
有关更多信息,请参阅此链接:https: //www.postgresql.org/docs/8.0/sql-alteruser.html
回答by Shubham Singh
In windows postgres stores password for automatic login at following path (only if you would have selected password save option while installation)
在 Windows postgres 中存储密码以在以下路径自动登录(仅当您在安装时选择了密码保存选项)
C:\Users\USERNAME\AppData\Roaming\postgresql\pgpass.conf
C:\Users\USERNAME\AppData\Roaming\postgresql\pgpass.conf
you can open this file in a text editor and see your password.
您可以在文本编辑器中打开此文件并查看您的密码。