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';"

Revision #1
Created 19 May 2026 16:20:25 by Admin
Updated 19 May 2026 16:20:42 by Admin