How to create a new user with a password in PostgreSQL in ubuntu 18.04

First you have to switch to postgres user.

 sudo -i -u postgres  

See the output.


Then type the command given below.

createuser --interactive 


See the output. Just enter a user name (“john”) as you wish.


Press enter.

Then system will ask to create this user with super user privileges. If you type “y” user will be created with super user privileges.



Now user “john” has been created successfully. Then we will add a password for user john.

psql -d template1 -c "ALTER USER john WITH PASSWORD 'newpassword';"

See the output.


Done. The password has been added successfully. Check whether user was created by using any tool like pgAdmin.





Leave a Comment