如何更改 PostgreSQL 用户密码?

如何更改 PostgreSQL 用户的密码?

答案

sudo -u user_name psql db_name
ALTER USER user_name WITH PASSWORD 'new_password';
$ sudo -u postgres psql
\password postgres
\q
local   all             all                                     peer
local   all             all                                     md5
$ sudo service postgresql restart
ALTER USER username WITH ENCRYPTED PASSWORD 'password';
\password
sudo -u <user_name> psql -c "ALTER USER <user_name> PASSWORD '<new_password>';"
Database administrative login by Unix domain socket
local      all              postgres                                md5
Database administrative login by Unix domain socket
local   all             postgres                                peer
sudo -u postgres psql
\password postgres
sudo -u postgres psql -c "\password"
local   all   all   trust
ALTER USER <username> WITH PASSWORD '<new_password>';  -- change password
ALTER USER <old_username> RENAME TO <new_username>;    -- rename user
CREATE USER <username> PASSWORD '<password>' IN GROUP <group>;
DROP USER <username>;
ALTER GROUP <old_group> DROP USER <username>;
ALTER GROUP <new_group> ADD USER <username>;