ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

PostgreSQL:修改数据库用户的密码

2022-11-10 12:37:01  阅读:455  来源: 互联网

标签:postgresql SQL 数据库 密码 用户


1. psql.bin: FATAL: password authentication failed for user "postgres"

#su postgres -bash-3.2$psql -U postgres postgres=#alter user postgres with password new password; postgres=#q

这种修改方式是错误的,重新登录postgres用户,会提示以下错误信息:

psql.bin: FATAL: password authentication failed for user "postgres"

因为 postgreSQL数据库用户和密码 与 Linux 用户postgres的密码是独立存储的,所以 修改数据库密码 需要修改 数据库用户角色的密码 而不是Linux用户的密码。

针对以上问题, 可以按一下步骤:

(1)先把pg_hba.conf 中 远程Ip对应的Method 改为 trust,保存后,重新加载 pg_hba.conf

postgres@ubuntu:~/bin$ ./pg_ctl reload server signaled

(2)然后,在pgadmin客户端中使用修改过的密码进行登录,登录进去后,执行以下命令:

alter role postgres with password yourpassword

(3)接下来,需要重新在Linux shell中登录 postgres

root@ubuntu:~# su - postgres $ psql Password: psql.bin (9.5.13) Type "help" for help. No entry for terminal type "xterm"; using dumb terminal settings. postgres=#

(4)然后,执行以下命令,查看当前postgresql 有多少用户,及对应的密码

postgres=# select rolname,rolpassword from pg_authid;

(5) 再次执行以下命令:

postgres=# alter role postgres with password yourpassword;

(6)之后,退出postgres 用户,切换为root 用户, 修改pg_hba.conf,把 trust 改为 MD5, 退出并保存。重新加载pg_hba.conf。

(7)走到这里, 就可以成功的 使用 postgres用户和新密码yourpassword登录到pg了。

2.正确的修改postgresql数据库 某用户的密码的方式如下:

alter role postgres with password yourpassword

标签:postgresql,SQL,数据库,密码,用户
来源:

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有