I follow a tutorial at https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-22-04-quickstart . I buy a Virtual Private Server (VPC) what use Ubuntu 22.04 LTS , 4 GB RAM, 100 GB SSD disk, 2 cores. My commands:

sudo apt update
sudo apt install postgresql postgresql-contrib
sudo -i -u postgres

enter image description here

In this case, How to set password postgres for user postgres on PostgreSQL 14.5 on Ubuntu 22.04.1 LTS?

  • You do not set the password to postgres. You are on the road to hell. Sep 19, 2022 at 4:21

2 Answers 2


Try to use \password <username> when You are logged to DB, after that You will be asked to enter password twice


In general, you can use the ALTER ROLE command to set the password.

 ALTER ROLE postgres WITH PASSWORD 'postgres';

Reference: ALTER ROLE (PostgreSQL | Docs)

But setting a password on the postgres user seems counter-productive. If you're connecting locally you have identity authentication, so a password is not needed. If you're connecting over a network the postgres account is a prime target for password guessing attacks, so it's better to create an alternative database superuser account and use that.

 CREATE ROLE mydbadmin WITH SUPERUSER PASSWORD 'correct_horse_battery_staple';

Reference: CREATE ROLE (PostgreSQL | Docs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.