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

2022/11/11 2:23:54

本文主要是介绍PostgreSQL:修改数据库用户的密码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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:修改数据库用户的密码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程