忘記 PostgreSQL 的管理者密碼該如何重新設定?
5 月.30, 2010 in Database
若是因為太久沒有使用而忘記 PostgreSQL 資料庫的管理者 postgres 帳號的密碼, 可以用下列的過程來重新設定:
修改用戶端認證設定檔 pg_hba.conf 將原來的 local 設定給註解掉, 例如:
#local all all XXXX
增加一行設定
local all all trust
存檔後重新啟動 postgresql 服務後就可以在主機上免密碼登入
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@bestlong ~]# psql -U postgres template1 Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit template1=# alter user postgres password 'YourNewPassword'; ALTER ROLE template1=# \q [root@bestlong ~]# |
將密碼重設之後再還原 pg_hba.conf 的設定與重新啟動 postgresql 服務, 以回復到原來的安全性
Tags: PostgreSQL
Leave a Reply