
## Synopsis

Use the `SET ROLE` statement to set the current user of the current session to be the specified user.

## Syntax

{{%ebnf%}}
  set_role,
  reset_role
{{%/ebnf%}}

## Semantics

The specified `role_name` must be a role that the current session user is a member of. Superusers can set to any role.

After the role is set to `role_name`, any further SQL commands will use the privileges available to that role.

To reset the role back to current user, `RESET ROLE` or `SET ROLE NONE` can be used.

## Examples

- Change to new role John.

    ```plpgsql
    SELECT session_user, current_user;
    ```

    ```output
     session_user | current_user
    --------------+--------------
     yugabyte     | yugabyte
    (1 row)
    ```

    ```sql
    SET ROLE john;
    ```

    ```output
    SET
    ```

    ```sql
    SELECT session_user, current_user;
    ```

    ```output
     session_user | current_user
    --------------+--------------
     yugabyte     | john
    (1 row)
    ```

- Changing to new role assumes the privileges available to that role.

    ```plpgsql
    SELECT session_user, current_user;
    ```

    ```output
     session_user | current_user
    --------------+--------------
     yugabyte     | yugabyte
    (1 row)
    ```

    ```sql
    CREATE DATABASE db1;
    ```

    ```output
    CREATE DATABASE
    ```

    ```sql
    SET ROLE john;
    ```

    ```output
    SET
    ```

    ```sql
    SELECT session_user, current_user;
    ```

    ```output
     session_user | current_user
    --------------+--------------
     yugabyte     | john
    (1 row)
    ```

    ```sql
    CREATE DATABASE db2;
    ```

    ```output
    ERROR:  permission denied to create database
    ```

## See also

- [CREATE ROLE](../dcl_create_role)
- [GRANT](../dcl_grant)
- [REVOKE](../dcl_revoke)
