PostgreSQL:修改數(shù)據(jù)庫用戶的密碼

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):

PostgreSQL 9.5.3 中文手冊(cè)

PostgreSQL口令認(rèn)證的問題

關(guān)于連接PostgreSQL時(shí)提示 FATAL: password authentication failed for user "連接用戶名" 的解決辦法

你可能感興趣:

你可能感興趣windows上修改在用用戶的密碼

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容