Managing shard groups in a ClickHouse® cluster
You can arrange several shards of a ClickHouse® cluster into a shard group and then place tables in that group.
Getting a list of shard groups in a cluster
- In the management console
, select the folder containing the cluster. - Navigate
to Managed Service for ClickHouse. - Click the name of your cluster and select the Shard groups tab.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating 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 get a list of shard groups in a cluster, run this command:
yc managed-clickhouse shard-groups list \
--cluster-name=<cluster_name>
You can get the cluster name with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.ListShardGroups method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/shardGroups'You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.ListShardGroups method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.ListShardGroupsYou can get the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
Getting detailed information about a shard group
- In the management console
, select the folder containing the cluster. - Navigate
to Managed Service for ClickHouse. - Click the name of your cluster and select the Shard groups tab.
- Select the shard group to view detailed information.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating 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 detailed information about a shard group in a cluster, run this command:
yc managed-clickhouse shard-groups get \
--cluster-name=<cluster_name> \
--name=<shard_group_name>
You can get the cluster name from the list of clusters in your folder.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.GetShardGroup method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/shardGroups/<shard_group_name>'You can get the cluster ID with the list of clusters in the folder, and the shard group name, with the list of groups in the cluster.
-
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.GetShardGroup method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "shard_group_name": "<shard_group_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.GetShardGroupYou can get the cluster ID with the list of clusters in the folder, and the shard group name, with the list of groups in the cluster.
-
View the server response to make sure your request was successful.
Creating a shard group
-
In the management console
, select the folder containing the cluster. -
Navigate
to Managed Service for ClickHouse. -
Click the name of your cluster and select the Shard groups tab.
-
Click Create shard group in the top-right corner of the page.
-
Enter a name for the shard group.
A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
In the Shards field, select the shards to include in the group.
-
Optionally, add external shards to the group:
-
Click Add external shard.
-
Enter a name for the external shard.
A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
Specify the shard weight.
By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
Under Collecting management events, configure the external shard replica settings:
-
In the Host field, specify the host's FQDN or IP address.
Learn how to get a host FQDN in this guide.
-
In the Port field, specify the ClickHouse® connection port.
-
Enable Secure connection to use SSL/TLS encryption when connecting to the host.
-
In the User and Password fields, specify the username and password for access to the ClickHouse® database.
-
In the Priority field, specify the host priority.
The host priority is used to balance connections to the shard. The default value is
0. A lower value assigns a higher priority when selecting a host for shard connections.
To add another replica, click Add replica.
-
-
-
Click Apply.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating 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 shard group in a cluster, run this command:
yc managed-clickhouse shard-groups create \
--cluster-name=<cluster_name> \
--name=<shard_group_name> \
--description="<shard_group_description>" \
--shards=<list_of_shard_names> \
--external-shard name=<shard_name>,`
`weight=<shard_weight> \
--external-shard-replica shard=<shard_name>,`
`host=<host_FQDN_or_IP_address>,`
`port=<port>,`
`secure=<use_SSL_connection>,`
`user=<username>,`
`password=<password>,`
`priority=<host_priority>
Where:
-
--cluster-name: Cluster name you can request with the list of clusters in the folder. -
--name: Shard group name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--description: Shard group description. -
--shards: List of cluster shard names.You can get the shard names with the list of shards in the cluster.
-
--external-shard: External shard settings. This parameter is specified separately for each external shard and has the following structure:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
.
-
-
--external-shard-replica: External shard replica settings. This parameter is specified separately for each replica and has the following structure:-
shard: Name of the external shard the replica belongs to. -
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
Open the current Terraform configuration file with the infrastructure plan.
For more on how to create such a file, see Creating a cluster.
-
Add the
shard_groupsection to the Managed Service for ClickHouse® cluster description.resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" { ... shard_group { name = "<shard_group_name>" description = "<shard_group_description>" shard_names = [ "<shard_1_name>", ... "<shard_N_name>" ] external_shard { name = "<shard_name>" weight = <shard_weight> replica { host = "<host_FQDN_or_IP_address>" port = <port> secure = <use_SSL_connection> user = "<username>" password = "<password>" priority = <host_priority> } } } }Where:
-
name: Shard group name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
description: Shard group description. -
shard_names: List of cluster shard names. -
external_shard: External shard settings. This section is specified separately for each external shard and includes the following parameters:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
replica: External shard replica settings. This section is specified separately for each replica and includes the following parameters:-
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
-
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
Run this command to view the intended changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
Timeouts
The Terraform provider sets the following timeouts for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring from a backup: 60 minutes.
- Updating a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the timeout are aborted.
How to change these limits
Add the timeouts section to your cluster description, such as the following:
resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
...
timeouts = {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.CreateShardGroup method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/shardGroups' \ --data '{ "shardGroupName": "<shard_group_name>", "description": "<shard_group_description>", "shardNames": [ "<shard_1>", "<shard_2>", ... "<shard_N>" ], "externalShards" [ { "name": "<external_shard_1>", "weight": <shard_weight_when_writing_data>, "replicas": [ { "host": "<host_FQDN>", "port": "<port>", "secure": <use_SSL_connection>, "user": "<username>", "password": "<password>", "priority": <host_priority> }, { <host_2_parameters> }, ... { <host_N_parameters> } ] }, { <external_shard_2_parameters> }, ... { <external_shard_N_parameters> } ] }'Where:
-
shardGroupName: Shard group name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
description: Shard group description. -
shardNames: List of shards to include in the new group. -
externalShards: List of external shards to include in the new group. An external shard is a shard from another Managed Service for ClickHouse® cluster or a custom ClickHouse® installation. one per shard. Each element has the following structure:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
replicas: Shard host settings:-
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
You can get the cluster ID with the list of clusters in the folder.
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.CreateShardGroup method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "shard_group_name": "<shard_group_name>", "description": "<shard_group_description>", "shard_names": [ "<shard_1>", "<shard_2>", ... "<shard_N>" ], "external_shards" [ { "name": "<external_shard_1>", "weight": <shard_weight_when_writing_data>, "replicas": [ { "host": "<host_FQDN>", "port": <port>, "secure": <use_SSL_connection>, "user": "<username>", "password": "<password>", "priority": <host_priority> }, { <host_2_parameters> }, ... { <host_N_parameters> } ] }, { <external_shard_2_parameters> }, ... { <external_shard_N_parameters> } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.CreateShardGroupWhere:
-
shard_group_name: Shard group name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
description: Shard group description. -
shard_names: List of shards to include in the new group. -
external_shards: List of external shards to include in the new group. An external shard is a shard from another Managed Service for ClickHouse® cluster or a custom ClickHouse® installation. one per shard. Each element has the following structure:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
replicas: Shard host settings:-
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
You can get the cluster ID with the list of clusters in the folder.
-
-
View the server response to make sure your request was successful.
Updating a shard group
-
In the management console
, select the folder containing the cluster. -
Navigate
to Managed Service for ClickHouse. -
Click the name of your cluster and select the Shard groups tab.
-
Click
next to the shard group in question and select Edit. -
In the Shards field, select the shards to include in the group.
-
Under External shards:
-
Edit the shard that needs to be edited:
-
External shard name.
A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
Shard weight.
By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
Shard replica settings:
-
Host (FQDN or IP address).
Learn how to get a host FQDN in this guide.
-
Port for connection to ClickHouse®.
-
Secure connection.
If Secure connection is enabled, SSL/TLS encryption is used for connection to the host.
-
Username and password for access to the ClickHouse® database.
-
Host priority.
The host priority is used to balance connections to the shard. The default value is
0. A lower value assigns a higher priority when selecting a host for shard connections.
To add a replica, click Add replica.
-
-
-
To add an external shard, click Add external shard.
-
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating 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 update a shard group in a cluster, run this command:
yc managed-clickhouse shard-groups update \
--cluster-name=<cluster_name> \
--name=<shard_group_name> \
--description="<new_description_for_shard_group>" \
--shards=<new_list_of_shard_names> \
--external-shard name=<shard_name>,`
`weight=<shard_weight> \
--external-shard-replica shard=<shard_name>,`
`host=<host_FQDN_or_IP_address>,`
`port=<port>,`
`secure=<use_SSL_connection>,`
`user=<username>,`
`password=<password>,`
`priority=<host_priority>
Where:
-
--cluster-name: Cluster name you can request with the list of clusters in the folder. -
--name: Name of the edited shard group, which you can get with the list of shard groups in the cluster. -
--description: New description for the shard group. -
--shards: New list of cluster shard names. The new list will override the current one, so make sure it includes all the required shards.You can get the shard names with the list of shards in the cluster.
-
--external-shard: External shard settings. This parameter is specified separately for each external shard and has the following structure:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
.
Warning
When using
--external-shard, the new external shard settings will override the current ones. -
-
--external-shard-replica: External shard replica settings. This parameter is specified separately for each replica and has the following structure:-
shard: Name of the external shard the replica belongs to. -
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
Open the current Terraform configuration file with the infrastructure plan.
For more on how to create this file, see Creating a cluster.
-
In the Managed Service for ClickHouse® cluster description, update the
shard_groupsection for the shard group you need:resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" { ... shard_group { name = "<shard_group_name>" description = "<shard_group_description>" shard_names = [ "<shard_1_name>", ... "<shard_N_name>" ] external_shard { name = "<shard_name>" weight = <shard_weight> replica { host = "<host_FQDN_or_IP_address>" port = <port> secure = <use_SSL_connection> user = "<username>" password = "<password>" priority = <host_priority> } } } }Where:
-
name: Shard group name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
description: Shard group description. -
shard_names: List of cluster shard names. -
external_shard: External shard settings. This section is specified separately for each external shard and includes the following parameters:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
replica: External shard replica settings. This section is specified separately for each replica and includes the following parameters:-
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
-
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm resource changes.
-
Run this command to view the intended changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
Timeouts
The Terraform provider sets the following timeouts for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring from a backup: 60 minutes.
- Updating a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the timeout are aborted.
How to change these limits
Add the timeouts section to your cluster description, such as the following:
resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
...
timeouts = {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.updateShardGroup method, e.g., via the following cURL
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMaskparameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/shardGroups/<shard_group_name>' \ --data '{ "updateMask": "description,shardNames,externalShards", "description": "<shard_group_description>", "shardNames": [ "<shard_1>", "<shard_2>", ... "<shard_N>" ], "externalShards" [ { "name": "<external_shard_1>", "weight": <shard_weight_when_writing_data>, "replicas": [ { "host": "<host_FQDN>", "port": "<port>", "secure": <use_SSL_connection>, "user": "<username>", "password": "<password>", "priority": <host_priority> }, { <host_2_parameters> }, ... { <host_N_parameters> } ] }, { <external_shard_2_parameters> }, ... { <external_shard_N_parameters> } ] }'Where:
-
updateMask: Comma-separated string of settings to update. -
description: New description for the shard group. -
shardNames: New list of cluster shards to include in the group. To learn shard names, get the list of shards in the cluster. This list will replace the current one, so make sure you have added all the required shards to the new list. -
externalShards: List of external shards with updated settings to include in the group. An external shard is a shard from another Managed Service for ClickHouse® cluster or a custom ClickHouse® installation. one per shard. Each element has the following structure:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
replicas: Shard host settings:-
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
You can get the cluster ID with the list of clusters in the folder, and the shard group name, with the list of groups in the cluster.
-
-
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.UpdateShardGroup method, e.g., via the following gRPCurl
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_maskparameter as an array ofpaths[]strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "shard_group_name": "<shard_group_name>", "update_mask": { "paths": [ "description", "shard_names", "external_shards" ] }, "description": "<shard_group_description>", "shard_names": [ "<shard_1>", "<shard_2>", ... "<shard_N>" ], "external_shards" [ { "name": "<external_shard_1>", "weight": <shard_weight_when_writing_data>, "replicas": [ { "host": "<host_FQDN>", "port": <port>, "secure": <use_SSL_connection>, "user": "<username>", "password": "<password>", "priority": <host_priority> }, { <host_2_parameters> }, ... { <host_N_parameters> } ] }, { <external_shard_2_parameters> }, ... { <external_shard_N_parameters> } ] }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.UpdateShardGroupWhere:
-
update_mask: List of settings to update as an array of strings (paths[]). -
description: New description for the shard group. -
shard_names: New list of cluster shards to include in the group. To learn shard names, get the list of shards in the cluster. This list will replace the current one, so make sure you have added all the required shards to the new list. -
external_shards: List of external shards with updated settings to include in the group. An external shard is a shard from another Managed Service for ClickHouse® cluster or a custom ClickHouse® installation. one per shard. Each element has the following structure:-
name: Shard name.A name may include Latin letters, numbers, hyphens, and underscores. It must be from 1 to 63 characters long.
-
--weight: Shard weight within a group.By default, each external shard is assigned a weight of
100. If some shards (either external or the cluster's own) in the group have weights different from100, the data within the shard group will be distributed between the shards according to their weights.To calculate the shard's priority for data distribution within the group, the weight of each shard should be divided by the total weight of all shards in the group. For example, if an external shard has a weight of
100and a cluster shard has a weight of300, then the first shard's priority is1/4, and the second shard's priority is3/4. The higher the priority, the more data the shard will get.For more information, see this ClickHouse® guide
. -
replicas: Shard host settings:-
host: Host FQDN or IP address.Learn how to get a host FQDN in this guide.
-
port: Port for connecting to ClickHouse®. -
secure: Use an encrypted SSL/TLS connection when connecting to a host:trueorfalse. -
user,password: Username and password for access to the ClickHouse® database. -
priority: Host priority for balancing shard connections. The default value is0. A lower value assigns a higher priority when selecting a host for shard connections.
-
-
You can get the cluster ID with the list of clusters in the folder, and the shard group name, with the list of groups in the cluster.
-
-
View the server response to make sure your request was successful.
Deleting a shard group
Deleting a shard group does not affect the shards it contains, i.e., they remain in the cluster.
Tables created on the deleted group remain but become unusable: any attempts to query them will return errors. However, you can delete these tables before or after deleting the shard group.
- In the management console
, select the folder containing the cluster. - Navigate
to Managed Service for ClickHouse. - Click the name of your cluster and select the Shard groups tab.
- Click
next to the shard group in question and select Delete.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating 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 shard group in a cluster, run this command:
yc managed-clickhouse shard-groups delete \
--cluster-name=<cluster_name> \
--name=<shard_group_name>
You can get the cluster name from the list of clusters in your folder.
You can get the shard group name with the list of shard groups in the cluster.
-
Open the current Terraform configuration file with the infrastructure plan.
For more on how to create this file, see Creating a cluster.
-
Delete the
shard_groupsection for the group in question from the Managed Service for ClickHouse® cluster description. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Type
yesand press Enter.-
Run this command to view the intended changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
Timeouts
The Terraform provider sets the following timeouts for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring from a backup: 60 minutes.
- Updating a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the timeout are aborted.
How to change these limits
Add the timeouts section to your cluster description, such as the following:
resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
...
timeouts = {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.DeleteShardGroup method, e.g., via the following cURL
request:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/shardGroups/<shard_group_name>'You can get the cluster ID with the list of clusters in the folder, and the shard group name, with the list of groups in the cluster.
-
View the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.DeleteShardGroup method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "shard_group_name": "<shard_group_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.DeleteShardGroupYou can get the cluster ID with the list of clusters in the folder, and the shard group name, with the list of groups in the cluster.
-
View the server response to make sure your request was successful.
ClickHouse® is a registered trademark of ClickHouse, Inc