Updated on 2025-10-23 GMT+08:00

ALTER USER

Description

Modifies the attributes of a database user.

Precautions

Session parameters modified by ALTER USER apply to a specified user and take effect in the next session.

Syntax

  • Modify user permissions or other information.
    ALTER USER user_name [ [ WITH ] option [ ... ] ];
    ALTER USER user_name [ IN DATABASE database_name ]
        SET configuration_parameter {{ TO | = } { value | DEFAULT }|FROM CURRENT};
    ALTER USER user_name
        [ IN DATABASE database_name ] RESET ALL;
    

    The option clause is as follows:

    { CREATEDB | NOCREATEDB }
        | { CREATEROLE | NOCREATEROLE }
        | { AUDITADMIN | NOAUDITADMIN }
        | { SYSADMIN | NOSYSADMIN }
        | {MONADMIN | NOMONADMIN}
        | {OPRADMIN | NOOPRADMIN}
        | {POLADMIN | NOPOLADMIN}
        | { USEFT | NOUSEFT }
        | {INHERIT | NOINHERIT}
        | { LOGIN | NOLOGIN }
        | {PERSISTENCE | NOPERSISTENCE}
        | CONNECTION LIMIT connlimit
        | VALID BEGIN 'timestamp'
        | VALID UNTIL 'timestamp'
        | USER GROUP 'groupuser'
        | NODE GROUP logic_cluster_name
        | ACCOUNT { LOCK | UNLOCK }
  • Change the value of a specified parameter associated with the user.
    ALTER USER user_name [ IN DATABASE database_name ]
        SET configuration_parameter { { TO | = } { value | DEFAULT } | FROM CURRENT };
  • Reset the values of all parameter associated with the user.
    ALTER USER user_name 
        [ IN DATABASE database_name ] RESET ALL;

Parameters

  • user_name

    Specifies the current username.

    Value range: an existing username. For details about the username requirements, see •user_name.

  • new_password

    Specifies a new password.

    Ensure that the password:

    • Differ from the old password.
    • Contain at least eight characters. This is the default length.
    • Differ from the username or the reverse of the username.
    • Contain at least three of the following character types: uppercase characters, lowercase characters, digits, and special characters (limited to ~!@#$ %^&*()-_=+\|[{}];:,<.>/?).
    • Be enclosed by single quotation marks.

    Value range: a string.

  • old_password

    Specifies the old password.

  • ACCOUNT { LOCK | UNLOCK }
    • ACCOUNT LOCK: locks an account to forbid login to databases.
    • ACCOUNT UNLOCK: unlocks an account to allow login to databases.
  • PGUSER

    In the current version, the PGUSER attribute of a user cannot be modified.

For details about other parameters, see "Parameters" in CREATE ROLE and ALTER ROLE.

Examples

See Examples in CREATE USER.