Skip to content

PostgreSQL USER

    CREATE USER

    CREATE USER — define a new database role

    CREATE USER name [ [ WITH ] option [ ... ] ]
    where option can be:
          SUPERUSER | NOSUPERUSER
        | CREATEDB | NOCREATEDB
        | CREATEROLE | NOCREATEROLE
        | INHERIT | NOINHERIT
        | LOGIN | NOLOGIN
        | REPLICATION | NOREPLICATION
        | BYPASSRLS | NOBYPASSRLS
        | CONNECTION LIMIT connlimit
        | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
        | VALID UNTIL 'timestamp'
        | IN ROLE role_name [, ...]
        | IN GROUP role_name [, ...]
        | ROLE role_name [, ...]
        | ADMIN role_name [, ...]
        | USER role_name [, ...]
        | SYSID uid

    CREATE USER is now an alias for CREATE ROLE. The only difference is that when the command is spelled CREATE USERLOGIN is assumed by default, whereas NOLOGIN is assumed when the command is spelled CREATE ROLE.

    ALTER USER

    ALTER USER — change a database role

    ALTER USER role_specification [ WITH ] option [ ... ]
    where option can be:
          SUPERUSER | NOSUPERUSER
        | CREATEDB | NOCREATEDB
        | CREATEROLE | NOCREATEROLE
        | INHERIT | NOINHERIT
        | LOGIN | NOLOGIN
        | REPLICATION | NOREPLICATION
        | BYPASSRLS | NOBYPASSRLS
        | CONNECTION LIMIT connlimit
        | [ ENCRYPTED ] PASSWORD 'password' | PASSWORD NULL
        | VALID UNTIL 'timestamp'
    ALTER USER name RENAME TO new_name
    ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter { TO | = } { value | DEFAULT }
    ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter FROM CURRENT
    ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] RESET configuration_parameter
    ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] RESET ALL
    where role_specification can be:
        role_name
      | CURRENT_USER
      | SESSION_USER

    ALTER USER is now an alias for ALTER ROLE.

    DROP USER

    DROP USER — remove a database role

    DROP USER [ IF EXISTS ] name [, ...]

    DROP USER is simply an alternate spelling of DROP ROLE.