SET SESSION AUTHORIZATION

Synopsis

Use the SET SESSION AUTHORIZATION statement to set the current user and session user of the current session to be the specified user.

Syntax

  1. set_session_authorization ::= SET [ SESSION | LOCAL ] SESSION
  2. AUTHORIZATION { role_name | DEFAULT }
  3. reset_session_authorization ::= RESET SESSION AUTHORIZATION

set_session_authorization

SET SESSION AUTHORIZATION - 图1

reset_session_authorization

SET SESSION AUTHORIZATION - 图2

Semantics

Session user can only be changed by superusers.Once the session user is set to role_name, any further SQL commands will use the privileges available to that role.

To reset the session user back to current authenticated user, RESET SESSION AUTHORIZATION or SET SESSION AUTHORIZATION DEFAULT can be used.

Examples

  • Set session user to John.
  1. yugabyte=# select session_user, current_user;
  2. session_user | current_user
  3. --------------+--------------
  4. yugabyte | yugabyte
  5. (1 row)
  6. yugabyte=# set session authorization john;
  7. SET
  8. yugabyte=# select session_user, current_user;
  9. session_user | current_user
  10. --------------+--------------
  11. john | john
  12. (1 row)

See also