我可以通过这种方式更改postgresql用户密码(2步):
$ su - postgres -c 'psql -U postgres -d postgres'
# Alter user postgres with password 'password';
现在,我想使用单行命令(1步)更改密码,例如:
su - postgres -c 'psql -U postgres -d postgres -c "alter user postgres with password ''password'';"'
我听说使用双单引号来转义单引号,所以我添加了双引号'
.但是,它会显示错误消息:
ERROR: syntax error at or near "password"
LINE 1: alter user postgres with password password;
有人能告诉我如何使用一行命令来做这件事吗?