> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CREATE RESOURCE GROUP

The `CREATE RESOURCE GROUP` [statement](https://docs.cockroachlabs.com/docs/stable/sql-statements.md) creates a [resource group](https://docs.cockroachlabs.com/docs/stable/resource-groups.md), which sets the share of CPU that a workload receives when CPU is contended.

> [!NOTE]
>
> **This feature is in [preview](https://docs.cockroachlabs.com/docs/releases/cockroachdb-feature-availability.md)** and subject to change. To share feedback and/or issues, contact [Support](https://support.cockroachlabs.com).

To use `CREATE RESOURCE GROUP`, you must first [enable resource groups](https://docs.cockroachlabs.com/docs/stable/resource-groups.md#enable-resource-groups).

## Required privileges

Only members of the [`admin` role](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization#admin-role) can create resource groups.

## Synopsis

![create\_resource\_group syntax diagram](https://mintcdn.com/cockroachlabs/iBfszXHb4tKmDGVE/images/sql-diagrams/v26.4/create_resource_group.svg?fit=max\&auto=format\&n=iBfszXHb4tKmDGVE\&q=85\&s=bbfde96d960d1f5c5c9ac5c15e1c1f69)

## Parameters

| Parameter | Description |
| - | - |
| `IF NOT EXISTS` | Create the resource group only if a resource group with the same name does not exist. If one does exist, the statement does nothing and does not return an error. |
| `name` | The name of the resource group. The name must be unique among resource groups. |
| `with_resource_group_options` | The resource group options, written as `WITH (option = value, ...)`. For the supported options, refer to [Options](#options). |

### Options

| Option | Value | Description |
| - | - | - |
| `cpu_weight` | Positive integer | **Required.** The group's CPU weight. A group's share of CPU is its weight divided by the sum of the weights of all user-defined resource groups. For details, refer to [How CPU is shared](https://docs.cockroachlabs.com/docs/stable/resource-groups.md#how-cpu-is-shared). |
| `max_cpu` | `BOOL` | Whether the group stays in the burst tier when it uses more than its share of CPU. If omitted, `max_cpu` is `false`. For details, refer to [`max_cpu`](https://docs.cockroachlabs.com/docs/stable/resource-groups#max_cpu). |

## Examples

### Create a resource group

The following statement creates a resource group named `reporting` with a CPU weight of `100`:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE RESOURCE GROUP reporting WITH (cpu_weight = 100);
```

Create a second resource group named `oltp` with a larger weight. Set `max_cpu` so that the group stays in the burst tier when it uses more than its share:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE RESOURCE GROUP oltp WITH (cpu_weight = 300, max_cpu = true);
```

To view the resource groups and their CPU shares, use [`SHOW RESOURCE GROUPS`](https://docs.cockroachlabs.com/docs/stable/show-resource-groups):

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SHOW RESOURCE GROUPS;
```

```
  id |   name    | cpu_weight | max_cpu | cpu_share_percent
-----+-----------+------------+---------+--------------------
  17 | oltp      |        300 |    t    |                75
  18 | reporting |        100 |    f    |                25
(2 rows)
```

### Create a resource group only if it does not exist

The following statement does nothing, because a resource group named `reporting` already exists:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE RESOURCE GROUP IF NOT EXISTS reporting WITH (cpu_weight = 50);
```

Without `IF NOT EXISTS`, the statement returns an error:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
CREATE RESOURCE GROUP reporting WITH (cpu_weight = 50);
```

```
ERROR: resource group "reporting" already exists
SQLSTATE: 42710
```

### Assign sessions to a new resource group

After you create a resource group, assign sessions to it with the `resource_group` [session variable](https://docs.cockroachlabs.com/docs/stable/set-vars.md). The following statement assigns all future sessions of the `report_user` role to the `reporting` group:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
ALTER ROLE report_user SET resource_group = 'reporting';
```

For all of the ways to assign sessions to a resource group, refer to [Assign workloads to a resource group](https://docs.cockroachlabs.com/docs/stable/resource-groups.md#assign-workloads-to-a-resource-group).

## See also

* [Resource Groups](https://docs.cockroachlabs.com/docs/stable/resource-groups.md)
* [`ALTER RESOURCE GROUP`](https://docs.cockroachlabs.com/docs/stable/alter-resource-group)
* [`DROP RESOURCE GROUP`](https://docs.cockroachlabs.com/docs/stable/drop-resource-group)
* [`SHOW RESOURCE GROUPS`](https://docs.cockroachlabs.com/docs/stable/show-resource-groups)
* [SQL Statements](https://docs.cockroachlabs.com/docs/stable/sql-statements.md)
