---
title: "SET ROLE"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/dcl_set_role/"
---

# SET ROLE

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

## Synopsis

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

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-1)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-1)

```output.ebnf
set_role ::= SET [ SESSION | LOCAL ] ROLE { role_name | NONE }

reset_role ::= RESET ROLE
```

#### set\_role

SETSESSIONLOCALROLE[role\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#role-name)NONE

#### reset\_role

RESETROLE

## 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](/stable/api/ysql/the-sql-language/statements/dcl_create_role "CREATE ROLE")
- [GRANT](/stable/api/ysql/the-sql-language/statements/dcl_grant "GRANT")
- [REVOKE](/stable/api/ysql/the-sql-language/statements/dcl_revoke "REVOKE")
