To change the password for the postgres user, type the command:
$ sudo passwd postgres
After executing the command the following messages will appear:
Digite a nova senha UNIX:
Redigite a nova senha UNIX:
Enter your password and retype it later. After that, we will log in with the postgres user.
$ su postgres
The password that will be required is the same as the one we just changed.
Now let's change the password to connect to the bank.
This command is for version 7 or higher:
$ psql -c "ALTER USER postgres WITH PASSWORD 'nova_senha'" -d template1
nova_senha will be the password you want.
Source: vivaolinux .