[Yandex Cloud documentation](../../index.md) > [Yandex MPP Analytics for PostgreSQL](../index.md) > [Step-by-step guides](index.md) > Users and sessions > Managing resource groups

# Managing resource groups

You can manage cluster resource usage quotas via [resource groups](../concepts/resource-groups.md).

To perform operations using SQL queries, [connect to the cluster](connect/index.md) as a user with the `mdb_admin` [role](../concepts/cluster-users.md#mdb_admin).

## View information about resource groups {#info}

{% list tabs group=instructions %}

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To view a list of resource groups and their [parameter](../concepts/resource-groups.md#parameters) values, run the command:

    ```bash
    yc managed-greenplum resource-groups list --cluster-id=<cluster_ID> 
    ```

    To view the parameter values of a specific resource group, run this command:

    ```bash
    yc managed-greenplum resource-groups get <resource_group_name> \
       --cluster-id=<cluster_ID> 
    ```

    You can replace `--cluster-id` with `--cluster-name`. You can get the cluster ID and name with the [list of clusters](cluster-list.md#list-clusters) in the folder.

- SQL {#sql}

    To view a list of resource groups and their [parameter](../concepts/resource-groups.md#parameters) values, run the command:

    ```sql
    SELECT * FROM gp_toolkit.gp_resgroup_config;
    ```

    To view a list of roles and the resource groups they belong to, run this command:

    ```sql
    SELECT rolname, rsgname FROM pg_roles, pg_resgroup
    WHERE pg_roles.rolresgroup=pg_resgroup.oid;
    ```

{% endlist %}

## Create a resource group {#create}

{% list tabs group=instructions %}

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
    
    To create a resource group in an Apache Cloudberry™ cluster, provide the name of the resource group and the values of its [parameters](../concepts/resource-groups.md#parameters) in this command:

    ```bash
    yc managed-greenplum resource-groups create <resource_group_name> \
       --cluster-id <cluster_ID> \
       --concurrency <CONCURRENCY_parameter_value> \
       --cpu-max-percent <CPU_MAX_PERCENT_parameter_value> \
       --cpu-weight <CPU_WEIGHT_parameter_value> \
       --memory-quota <MEMORY_QUOTA_parameter_value> \
       --min-cost <MIN_COST_parameter_value>
    ```

    When creating a resource group, just specify the value of the `CPU_MAX_PERCENT` parameter. The other parameters will be set to defaults.

    To create a resource group in a Greenplum® cluster, provide the name of the resource group and the values of its [parameters](../concepts/resource-groups.md#parameters) in this command:
   
    ```bash
    yc managed-greenplum resource-groups create <resource_group_name> \
       --cluster-id <cluster_ID> \
       --concurrency <CONCURRENCY_parameter_value> \
       --cpu-rate-limit <CPU_RATE_LIMIT_parameter_value> \
       --memory-limit <MEMORY_LIMIT_parameter_value> \
       --memory-shared-quota <MEMORY_SHARED_QUOTA_parameter_value> \
       --memory-spill-ratio <MEMORY_SPILL_RATIO_parameter_value>
    ```

    When creating a resource group, just specify the value of the `CPU_RATE_LIMIT` parameter. The other parameters will be set to defaults.

    You can replace `--cluster-id` with `--cluster-name`. You can get the cluster ID and name with the [list of clusters](cluster-list.md#list-clusters) in the folder.

- SQL {#sql}

    Provide the name of the resource group and its [parameters](../concepts/resource-groups.md#parameters) in the command:

    ```sql
    CREATE RESOURCE GROUP <resource_group_name> WITH (<parameter_1>, <parameter_2>, ...);
    ```

    When creating a resource group, just specify the value of the `CPU_RATE_LIMIT` or `CPUSET` parameter. The other parameters will be set to defaults.


{% endlist %}

## Assign a resource group to a role {#assign}

{% list tabs group=instructions %}

- SQL {#sql}

    To create a role and immediately assign it to a resource group, run this command:

    ```sql
    CREATE ROLE <role_name> RESOURCE GROUP <resource_group_name>;
    ```

    {% note info %}

    * If no resource group is specified when creating a role, the role is assigned to `default_group`.

    * In Apache Cloudberry™, roles with the [SUPERUSER attribute](../concepts/cluster-users.md#attributes) are assigned to `admin_group`.

    {% endnote %}

    To assign a different resource group to the role, run this command:

    ```sql
    ALTER ROLE <role_name> RESOURCE GROUP <resource_group_name>;
    ```

{% endlist %}

## View the current load on resource groups {#load}

{% list tabs group=instructions %}

- SQL {#sql}

    To view the current load on resource groups across the whole cluster, run this command:

    ```sql
    SELECT * FROM gp_toolkit.gp_resgroup_status;
    ```

    To view the same data by hosts, use this command:

    ```sql
    SELECT * FROM gp_toolkit.gp_resgroup_status_per_host;
    ```

    To view the same data by segments, use this command:

    ```sql
    SELECT * FROM gp_toolkit.gp_resgroup_status_per_segment;
    ```

{% endlist %}

## View a list of queries in resource groups {#queries}

{% list tabs group=instructions %}

- SQL {#sql}

    To see a list of queries in progress and in the queue, run this command:

    ```sql
    SELECT query, waiting, rsgname, rsgqueueduration
    FROM pg_stat_activity;
    ```

{% endlist %}

## Edit resource group settings {#params}

{% list tabs group=instructions %}

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To change the [parameters](../concepts/resource-groups.md#parameters) of a resource group in an Apache Cloudberry™ cluster, run the following command:

    ```bash
    yc managed-greenplum resource-groups update <resource_group_name> \
       --cluster-id <cluster_ID> \
       --concurrency <new_CONCURRENCY_value> \
       --cpu-max-percent <new_CPU_MAX_PERCENT_parameter_value> \
       --cpu-weight <new_CPU_WEIGHT_parameter_value> \
       --memory-quota <new_MEMORY_QUOTA_parameter_value> \
       --min-cost <new_MIN_COST_parameter_value>
    ```

    To change the [parameters](../concepts/resource-groups.md#parameters) of a resource group in a Greenplum® cluster, run the following command:

    ```bash
    yc managed-greenplum resource-groups update <resource_group_name> \
       --cluster-id <cluster_ID> \
       --concurrency <new_CONCURRENCY_value> \
       --cpu-rate-limit <new_CPU_RATE_LIMIT_value> \
       --memory-limit <new_MEMORY_LIMIT_value> \
       --memory-shared-quota <new_MEMORY_SHARED_QUOTA_value> \
       --memory-spill-ratio <new_MEMORY_SPILL_RATIO_value>
    ```

    You can replace `--cluster-id` with `--cluster-name`. You can get the cluster ID and name with the [list of clusters](cluster-list.md#list-clusters) in the folder.

- SQL {#sql}

    Provide the name of the resource group and the new values of its [parameters](../concepts/resource-groups.md#parameters) you want to change in the command:

    ```sql
    ALTER RESOURCE GROUP <resource_group_name> SET <setting_name> <new_setting_value>;
    ```

{% endlist %}

## Delete a resource group {#delete}

You can only delete a resource group if it is not assigned to any roles and contains no transactions in progress or in the queue.

{% list tabs group=instructions %}

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    To delete a resource group, run this command:

    ```bash
    yc managed-greenplum resource-groups delete <resource_group_name> \
       --cluster-id=<cluster_ID> 
    ```

    You can replace `--cluster-id` with `--cluster-name`. You can get the cluster ID and name with the [list of clusters](cluster-list.md#list-clusters) in the folder.

- SQL {#sql}

    To delete a resource group, run this command:

    ```sql
    DROP RESOURCE GROUP <resource_group_name>;
    ```

{% endlist %}


## Example of creating a resource group {#example}

Create a resource group with test specifications:

* Name: `testgroup`.
* Maximum number of processed transactions: 15.
* Share of CPU resources used in the segment: 10%.
* RAM share in the segment: 20%.
* Share allocated as an overall quota: 50%.
* RAM share in the resource group that a single transaction operator can occupy: 30%.

{% list tabs group=instructions %}

- CLI {#cli}

    If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

    The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

    Run this command:

    ```bash
    yc managed-greenplum resource-groups create testgroup \
       --cluster-id=<cluster_ID> \
       --concurrency=15 \
       --cpu-rate-limit=10 \
       --memory-limit=20 \
       --memory-shared-quota=50\
       --memory-spill-ratio=30
    ```

    Make sure the new resource group appeared in the list:

    ```bash
    yc managed-greenplum resource-groups list --cluster-id=<cluster_ID> 
    ```

- SQL {#sql}

    Run this command:

    ```sql
    CREATE RESOURCE GROUP testgroup
    WITH (CONCURRENCY=15, CPU_RATE_LIMIT=10, MEMORY_LIMIT=20, MEMORY_SHARED_QUOTA=50, MEMORY_SPILL_RATIO=30);
    ```

    Make sure the new resource group appeared in the list:

    ```sql
    SELECT * FROM gp_toolkit.gp_resgroup_config;
    ```

{% endlist %}


_Greenplum® and Greenplum Database® are registered trademarks or trademarks of Broadcom Inc. in the United States and/or other countries._

_Apache® and Apache Cloudberry™ are registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries._