Change password for postgres user in PostgreSQL

In order to change the password for the postgres user you should NEVER do this:

$ sudo passwd postgres

By default the postgres user is locked and if you change the password with passwd the account is immediately unlocked, thus anyone could login to the system with it. This could be very dangerous if you configure an easy password.

The proper way is doing it inside the psql terminal with the password command:

$ sudo -u postgres psql postgres
postgres=# password postgres
Enter new password: 
Enter it again: 
postgres=# q

Ref: http://serverfault.com/a/325596

You might also like

Change root password in MySQL
In GNU/Linux:$ sudo mysqld_safe --skip-grant-tables & $ mysql -u root -p #press enter to use a...

Fix ‘ERROR: column “spclocation” does not exist’ in phpPgAdmin
I was going to create a new database with phpPgAdmin and it crashed with this error:ERROR: column...

Fix ‘ERROR: column “spclocation” does not exist’ in phpPgAdmin
I was going to create a new database with phpPgAdmin and it crashed with this error:ERROR: column...

Change root’s password when sudoers file is misconfigured and sudo won’t work
If you misconfigure the sudoers file you may end up in a situation where you wouldn't be able to use...

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.