Search code examples
postgresqlshellubuntupostgresql-9.2createuser

How to add a user to PostgreSQL from the Ubuntu command line?


I want to add a user and give the createdb permission to it in the PostgreSQL from a Ubuntu command line! I know this can be done by going inside consul and run this:

ALTER USER joe CREATEDB

But I want to do it from Ubuntu command line!


Solution

  • Use createuser.
    While logged in to your server as the postgres OS user:

    createuser --createdb joe
    

    Or, if you are some other user with the necessary sudo privileges:

    sudo -u postgres createuser --createdb joe
    

    Find more command-line options in the manual or with:

    man createuser