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

SET SESSION AUTHORIZATION

Description

Sets the session user identifier and the current user identifier of the current session to the specified user.

Precautions

The session identifier can be changed only when the initial session user has the system administrator permissions. Otherwise, the system executes the command only when an authenticated username is specified.

Syntax

  • Set the session user identifier and current user identifier for the current session.
    SET [ SESSION | LOCAL ] SESSION AUTHORIZATION role_name PASSWORD 'password';
  • Reset the session and current user identifiers to the originally authenticated username.
    {SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
    | SET SESSION_AUTHORIZATION = DEFAULT};

Parameters

  • SESSION

    Specifies that the command takes effect only for the current session.

  • LOCAL

    Specifies that the command takes effect only for the current transaction.

  • role_name

    Specifies the username.

    Value range: a string. For details about the username requirements, see •user_name.

  • password

    Specifies the password for the role. The password must comply with the password convention. Encrypted passwords are not supported.

  • DEFAULT

    Resets the identifiers of the session and current users to the initially authenticated usernames.

Examples

-- Create a role named paul.
m_db=# CREATE ROLE paul IDENTIFIED BY '********';

-- Set the current user to paul.
m_db=# SET SESSION AUTHORIZATION paul password '********';

Query the current user.
m_db=# SELECT CURRENT_USER;

-- Reset the current user.
m_db=# SET SESSION_AUTHORIZATION = DEFAULT;

-- Drop the user.
m_db=# DROP USER paul;

Helpful Links

SET ROLE