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
這種修改方式是錯(cuò)誤的,重新登錄postgres用戶,會(huì)提示以下錯(cuò)誤信息:
psql.bin: FATAL: password authentication failed for user "postgres"
因?yàn)?postgreSQL數(shù)據(jù)庫用戶和密碼 與 Linux 用戶postgres的密碼是獨(dú)立存儲(chǔ)的,所以 修改數(shù)據(jù)庫密碼 需要修改 數(shù)據(jù)庫用戶角色的密碼 而不是Linux用戶的密碼。
針對(duì)以上問題, 可以按一下步驟:
(1)先把pg_hba.conf? 中 遠(yuǎn)程Ip對(duì)應(yīng)的Method 改為 trust,保存后,重新加載 pg_hba.conf
postgres@ubuntu:~/bin$ ./pg_ctl reload
server signaled
(2)然后,在pgadmin客戶端中使用修改過的密碼進(jìn)行登錄,登錄進(jìn)去后,執(zhí)行以下命令:
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)然后,執(zhí)行以下命令,查看當(dāng)前postgresql 有多少用戶,及對(duì)應(yīng)的密碼
postgres=# select rolname,rolpassword from pg_authid;

(5) 再次執(zhí)行以下命令:
postgres=# alter role postgres with password 'yourpassword';
(6)之后,退出postgres 用戶,切換為root 用戶, 修改pg_hba.conf,把 trust 改為 MD5, 退出并保存。重新加載pg_hba.conf。
(7)走到這里, 就可以成功的 使用 postgres用戶和新密碼yourpassword登錄到pg了。

2.正確的修改postgresql數(shù)據(jù)庫 某用戶的密碼的方式如下:
alter role postgres with password 'yourpassword'
參考文獻(xiàn):
關(guān)于連接PostgreSQL時(shí)提示 FATAL: password authentication failed for user "連接用戶名" 的解決辦法
你可能感興趣: