本文翻译自:How to change PostgreSQL user password?
如何更改PostgreSQL用户的密码?
#1楼
参考:https://stackoom.com/question/rNIt/如何更改PostgreSQL用户密码
#2楼
Then type: 然后输入:
$ sudo -u postgres psql
Then: 然后:
\password postgres
Then to quit psql
: 然后退出psql
:
\q
If that does not work, reconfigure authentication. 如果这样不起作用,请重新配置身份验证。
Edit /etc/postgresql/9.1/main/pg_hba.conf
(path will differ) and change: 编辑/etc/postgresql/9.1/main/pg_hba.conf
(路径会有所不同)并更改:
local all all peer
to: 至:
local all all md5
Then restart the server: 然后重新启动服务器:
$ sudo service postgresql restart
#3楼
For password less login: 对于少密码登录:
sudo -u user_name psql db_name
To reset the password if you have forgotten: 要忘记密码,请重设密码:
ALTER USER user_name WITH PASSWORD 'new_password';
#4楼
Configuration that I've got on my server was customized a lot and I managed to change password only after I set trust authentication in the pg_hba.conf
file : 我在服务器上获得的配置已大量自定义,并且只有在pg_hba.conf
文件中设置了信任身份验证之后,我才设法更改了密码:
local all all trust
Don't forget to change this back to password or md5 不要忘记将其更改回密码或md5
#5楼
Go to your Postgresql Config and Edit pg_hba.conf 转到您的Postgresql配置并编辑pg_hba.conf
sudo vim /etc/postgresql/9.3/main/pg_hba.conf
Then Change this Line : 然后更改此行:
Database administrative login by Unix domain socket
local all postgres md5
to : 至 :
Database administrative login by Unix domain socket
local all postgres peer
then Restart the PostgreSQL service via SUDO command then 然后通过SUDO命令重新启动PostgreSQL服务,然后
psql -U postgres
You will be now entered and will See the Postgresql terminal 现在您将进入,将看到Postgresql终端
then enter 然后输入
\\password
and enter the NEW Password for Postgres default user, After Successfully changing the Password again go to the pg_hba.conf and revert the change to "md5" 并输入Postgres默认用户的新密码,再次成功更改密码后,转到pg_hba.conf并将更改还原为“ md5”
now you will be logged in as 现在您将以
psql -U postgres psql -U postgres
with your new Password. 用您的新密码。
Let me know if you all find any issue in it. 让我知道您是否在其中找到任何问题。
#6楼
您可以并且应该已经加密了用户的密码:
ALTER USER username WITH ENCRYPTED PASSWORD 'password';