- Go to config directory
cd /etc/postgresql/<postgresql_version>/main
- Open and update file "pg_hba.conf" to dismiss all authentications for "postgres" user (normally line 85)
local all postgres peer
local all postgres trust
- Restart Postgresql service to apply new configuration
sudo service postgresql restart
- Login to postgresql with user "postgres" (without any authentications)
psql -U postgres
- Change password of this postgresql user
ALTER USER postgres WITH PASSWORD '<your password>';
- Reupdate file "pg_hba.conf" to apply password authentication for "postgres" user
local all postgres trust
local all postgres md5
- Restart Postgresql service to apply new configuration
sudo service postgresql restart
- Login to postgresql with user "postgres" (require password)
psql -U postgres