Postgres Createuser with Password from Terminal

Postgres Createuser with Password from Terminal

I'm using vagrant to setup a new Ubuntu machine. With provisioning I'm in the need to create a new postgres user. Currently I'm using:

sudo su postgres
createuser -P myuser

Unfortunately provisioning fails because a prompt needs to be filled with password (-P flag).

Is there a way to pass the password to createuser like createuser myuser --password test or echo test | createuser -P myuser?

1 Answer

sudo -u postgres
psql -c "create role NewRole with login password 'secret';"
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.