I can change the postgresql user password in this way (2 steps):
$ su - postgres -c 'psql -U postgres -d postgres'
# Alter user postgres with password 'password';
Now I want to use a single line command (1 step) to change the password such as:
su - postgres -c 'psql -U postgres -d postgres -c "alter user postgres with password ''password'';"'
I heard using double single quote to escape one single quote so I added double quote '
. However is shows error message:
ERROR: syntax error at or near "password"
LINE 1: alter user postgres with password password;
Could someone let me know how to use one line of command to do this?