Create a Superuser in postgres

Posted on Oct 13, 2022

Question

i'm looking for setup a Rails Environment with Vagrant, for that purpose the box it's been provisioned through bash shell method and includes among others this line:

sudo -u postgres createuser <superuserusername> -s with password '<superuserpassword>'

but i'm getting a configuration error, createuser: too many command-line arguments (first is "with")

can you help me with the correct syntax for create a Superuser with a password. Thanks

Answer

Do it in a single statement within psql:

CREATE ROLE username WITH LOGIN SUPERUSER PASSWORD 'password';

e.g

CREATE ROLE dummy WITH LOGIN SUPERUSER PASSWORD '123456';