> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for Set Role

# SET ROLE

Activates roles for the current user.

```sql theme={null}
SET ROLE {DEFAULT | NONE | role [,...] | ALL | ALL EXCEPT role [,...]}
```

<h2 id="set-default-role">
  SET DEFAULT ROLE
</h2>

Sets default roles to a user.

Default roles are automatically activated at user login. You can set as default only the previously granted roles. If the role isn't granted to a user, ClickHouse throws an exception.

```sql theme={null}
SET DEFAULT ROLE {NONE | role [,...] | ALL | ALL EXCEPT role [,...]} TO {user|CURRENT_USER} [,...] [ON CLUSTER cluster_name]
```

`ON CLUSTER` is accepted either right after `SET DEFAULT ROLE` or at the end of the query, and executes it on every
host of the cluster. `CURRENT_USER` is resolved on the initiator before the query is distributed. `SET ROLE` only
changes the current session and therefore takes no `ON CLUSTER` clause.

<h2 id="examples">
  Examples
</h2>

Set multiple default roles to a user:

```sql theme={null}
SET DEFAULT ROLE role1, role2, ... TO user
```

Set all the granted roles as default to a user:

```sql theme={null}
SET DEFAULT ROLE ALL TO user
```

Purge default roles from a user:

```sql theme={null}
SET DEFAULT ROLE NONE TO user
```

Set all the granted roles as default except for specific roles `role1` and `role2`:

```sql theme={null}
SET DEFAULT ROLE ALL EXCEPT role1, role2 TO user
```

Set default roles on every host of a cluster:

```sql theme={null}
SET DEFAULT ROLE role1 TO user ON CLUSTER my_cluster
SET DEFAULT ROLE ON CLUSTER my_cluster role1 TO user
```
