How to change the password of the user postgres
Method 1: Using psql (most common)
Connect to PostgreSQL and run:
sql
ALTER USER postgres WITH PASSWORD 'new_password_here';
Or for any other user:
sql
ALTER USER username WITH PASSWORD 'new_password_here';
Method 2: Using \password in psql (more secure — doesn't show in logs)
bash
sudo -u postgres psql
Then inside psql:
\password postgres
It will prompt you to enter the new password twice without echoing it to the terminal or logs.
Method 3: From the command line (Linux)
bash
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'new_password';"