sqldatabasepostgresqlubuntusuperuser

Create a Superuser in postgres


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.


Solution

  • Solved with:

    sudo -u postgres createuser -s -i -d -r -l -w <<username>>
    sudo -u postgres psql -c "ALTER ROLE <<username>> WITH PASSWORD '<<password>>';"
    

    I know is not an elegant solution, but for now it'll do 😊