[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for ClickHouse®](../index.md) > [Step-by-step guides](index.md) > Clusters > Managing hosts > Managing ClickHouse® hosts

# Managing ClickHouse® hosts

You can do the following with ClickHouse® hosts:

* [Get a list of cluster hosts](#list-hosts).
* [Create a host](#add-host).
* [Update ClickHouse® host settings](#update).
* [Restart a host](#restart).
* [Delete a host](#remove-host).

For information about moving ClickHouse® hosts to a different [availability zone](../../overview/concepts/geo-scope.md), see [this guide](host-migration.md#clickhouse-hosts).

{% note warning %}

If you created your cluster without [ClickHouse® Keeper](../concepts/replication.md#ck) support, you should [add at least three ZooKeeper hosts](zk-hosts.md#add-zk) before adding new hosts to any of the [shards](../concepts/sharding.md).

{% endnote %}

## Getting a list of cluster hosts {#list-hosts}

# Getting a list of cluster hosts

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
  1. Navigate to **Managed Service for&nbsp;ClickHouse**.
  1. Click the name of your cluster and select the **Hosts** tab.

- 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 get a list of cluster hosts, run this command:

  ```bash
  yc managed-clickhouse host list \
     --cluster-name=<cluster_name>
  ```

  ```text
  +----------------------------+--------------+---------+--------+---------------+
  |            NAME            |  CLUSTER ID  |  ROLE   | HEALTH |    ZONE ID    |
  +----------------------------+--------------+---------+--------+---------------+
  | rc1b...mdb.yandexcloud.net | c9qp71dk1... | MASTER  | ALIVE  | ru-central1-b |
  | rc1a...mdb.yandexcloud.net | c9qp71dk1... | REPLICA | ALIVE  | ru-central1-a |
  +----------------------------+--------------+---------+--------+---------------+
  ```

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

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.ListHosts](../api-ref/Cluster/listHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        curl \
            --request GET \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/hosts'
        ```

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

    1. View the [server response](../api-ref/Cluster/listHosts.md#yandex.cloud.mdb.clickhouse.v1.ListClusterHostsResponse) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService.ListHosts](../api-ref/grpc/Cluster/listHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        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.ListHosts
        ```

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

    1. View the [server response](../api-ref/grpc/Cluster/listHosts.md#yandex.cloud.mdb.clickhouse.v1.ListClusterHostsResponse) to make sure your request was successful.

{% endlist %}

## Creating a host {#add-host}

The number of hosts in Managed Service for ClickHouse® clusters is limited by the CPU and RAM quotas allocated to database clusters in your cloud. To check the resources currently in use, open the [Quotas](https://console.yandex.cloud/cloud?section=quotas) page and find **Managed Databases**.

You can create several hosts in a cluster in one go.

To prevent data loss, the new host automatically inherits the data schema from existing hosts.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
  1. Navigate to **Managed Service for&nbsp;ClickHouse**.
  1. Click the cluster name and navigate to the **Hosts** tab.
  1. Click **Create ClickHouse hosts**.

  1. Specify the following host settings:

      
      * Availability zone.
      * Subnet (if the required subnet is not on the list, [create it](../../vpc/operations/subnet-create.md)).
      * Shard name.
      * Enable **Public access** if you want the host to be accessible from outside of Yandex Cloud.


  1. Optionally, click **Create host** to add more hosts and specify their parameters.

  1. Click **Create hosts** to create one or multiple hosts.

- 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 one or multiple hosts:

  
  1. To choose a subnet for your new host, get the list of all cluster subnets:

     ```bash
     yc vpc subnet list
     ```

     Result:

     ```text
     +-----------+-----------+------------+---------------+------------------+
     |     ID    |   NAME    | NETWORK ID |     ZONE      |      RANGE       |
     +-----------+-----------+------------+---------------+------------------+
     | b0cl69... | default-d | enp6rq7... | ru-central1-d | [172.16.0.0/20]  |
     | e2lkj9... | default-b | enp6rq7... | ru-central1-b | [10.10.0.0/16]   |
     | e9b0ph... | a-2       | enp6rq7... | ru-central1-a | [172.16.32.0/20] |
     | e9b9v2... | default-a | enp6rq7... | ru-central1-a | [172.16.16.0/20] |
     +-----------+-----------+------------+---------------+------------------+
     ```

     If the required subnet is not on the list, [create it](../../vpc/operations/subnet-create.md).


  1. View the description of the CLI command for creating hosts:

     ```bash
     yc managed-clickhouse hosts add --help
     ```

  1. Run the command to create hosts.

     Specify one or multiple `--host` parameters in the command, one for each new host.

     The command for creating a single host is as follows:

     
     ```bash
     yc managed-clickhouse hosts add \
       --cluster-name=<cluster_name> \
       --host zone-id=<availability_zone>,`
         `subnet-id=<subnet_ID>,`
         `assign-public-ip=<public_access_to_host>,`
         `shard-name=<shard_name>,`
         `type=clickhouse
     ```

     Where `assign-public-ip` is internet access to the host via a public IP address, `true` or `false`.


     Managed Service for ClickHouse® will start creating hosts.

     
     You should specify the subnet ID if the availability zone contains more than one subnet; otherwise, Managed Service for ClickHouse® will automatically select the only subnet. You can get the cluster name from the [list of clusters in your folder](cluster-list.md#list-clusters).



- Terraform {#tf}

  1. Open the current Terraform configuration file with the infrastructure plan.

     For more on how to create such a file, see the [Creating a cluster](cluster-create.md) section.

  1. Add a new host to the `hosts` section:

     ```hcl
     resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
       ...
       hosts = {
         ...
         <host_name> = {
           type             = "CLICKHOUSE"
           zone             = "<availability_zone>"
           subnet_id        = "<subnet_ID>"
           assign_public_ip = <public_access_to_host>
           shard_name       = "<shard_name>"
         }
       }
     }
     ```

     Where `assign_public_ip` is internet access to the host via a public IP address, `true` or `false`.

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm resource changes.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If 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.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more information, see [this Terraform provider guide](../../terraform/resources/mdb_clickhouse_cluster.md).

  {% note warning "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.
  
  {% cut "How to change these limits" %}
  
  Add the `timeouts` section to your cluster description, such as the following:
  
  ```hcl
  resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
    ...
    timeouts = {
      create = "1h30m" # 1 hour 30 minutes
      update = "2h"    # 2 hours
      delete = "30m"   # 30 minutes
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}


- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and place it in an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.AddHosts](../api-ref/Cluster/addHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

        
        ```bash
        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>/hosts:batchCreate' \
            --data '{
                      "hostSpecs": [
                        {
                          "type": "CLICKHOUSE",
                          "zoneId": "<availability_zone>",
                          "subnetId": "<subnet_ID>",
                          "shardName": "<shard_name>",
                          "assignPublicIp": <public_access_to_host>
                        },
                        { <similar_settings_for_new_host_2> },
                        { ... },
                        { <similar_settings_for_new_host_N> }
                      ],
                    }'
        ```


        Where `hostSpecs` is the array of settings for the new hosts. Each array element contains the configuration for a single host and has the following structure:

       * `type`: Host type, which is always `CLICKHOUSE` for ClickHouse® hosts.
       * `zoneId`: Availability zone.
       * `subnetId`: Subnet ID.
       * `shardName`: Shard name.
       * `assignPublicIp`: Host accessibility from the internet via a public IP address, `true` or `false`.

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

    1. View the [server response](../api-ref/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService.AddHosts](../api-ref/grpc/Cluster/addHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        
        ```bash
        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>",
                    "host_specs": [
                        {
                            "type": "CLICKHOUSE",
                            "zone_id": "<availability_zone>",
                            "subnet_id": "<subnet_ID>",
                            "shard_name": "<shard_name>",
                            "assign_public_ip": <public_access_to_host>
                        },
                        { <similar_settings_for_new_host_2> },
                        { ... },
                        { <similar_settings_for_new_host_N> }
                    ],
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.clickhouse.v1.ClusterService.AddHosts
        ```


        Where `host_specs` is the array of settings for the new hosts. Each array element contains the configuration for a single host and has the following structure:

       * `type`: Host type, which is always `CLICKHOUSE` for ClickHouse® hosts.
       * `zone_id`: Availability zone.
       * `subnet_id`: Subnet ID.
       * `shard_name`: Shard name.
       * `assign_public_ip`: Host accessibility from the internet via a public IP address, `true` or `false`.

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

    1. View the [server response](../api-ref/grpc/Cluster/addHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

{% note warning %}


If you cannot [connect](connect/clients.md) to the host you created, check that the cluster [security group](../concepts/network.md#security-groups) is configured correctly for the host subnet.


{% endnote %}


## Updating a host {#update}

You can change public access settings for any host in a Managed Service for ClickHouse® cluster.

{% note warning %}

For a more secure cluster with public host access enabled, use only trusted IP addresses or subnets in the cluster's security group rules. Learn more in [Configuring security groups](connect/index.md#configuring-security-groups).

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  To change the cluster host settings:
  1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
  1. Navigate to **Managed Service for&nbsp;ClickHouse**.
  1. Click the cluster name and navigate to the **Hosts** tab.
  1. Click ![image](../../_assets/console-icons/ellipsis.svg) in the host row and select **Edit**.
  1. In the window that opens, enable **Public access** to make the host accessible from outside Yandex Cloud, if required.
  1. Click **Save**.

- 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 host settings, run this command:

  ```bash
  yc managed-clickhouse host update <host_name> \
    --cluster-name=<cluster_name> \
    --assign-public-ip=<public_access_to_host>
  ```

  Where `assign-public-ip` is internet access to the host via a public IP address, `true` or `false`.

  You can get the host name with the [list of cluster hosts](#list-hosts), and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).


- Terraform {#tf}

  1. Open the current Terraform configuration file with the infrastructure plan.

     For more on how to create such a file, see the [Creating a cluster](cluster-create.md) section.

  1. Under `hosts`, add or change the `assign_public_ip` parameter value for the host:

     ```hcl
     resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
       ...
       hosts = {
         ...
         <host_name> = {
           ...
           assign_public_ip = <public_access_to_host>
         }
       }
     }
     ```

     Where `assign_public_ip` is internet access to the host via a public IP address, `true` or `false`.

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Confirm resource changes.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If 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.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more information, see [this Terraform provider guide](../../terraform/resources/mdb_clickhouse_cluster.md).


- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.UpdateHosts](../api-ref/Cluster/updateHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

        {% note 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 `updateMask` parameter as a single comma-separated string.
        
        {% endnote %}

        ```bash
        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>/hosts:batchUpdate' \
            --data '{
                      "updateHostSpecs": [
                        {
                          "hostName": "<host_name>",
                          "updateMask": "assignPublicIp",
                          "assignPublicIp": <public_access_to_host>
                        }
                      ]
                    }'
        ```

        Where `updateHostSpecs[]` is the list of hosts and their parameters to update. Below is the structure of an individual element:

        * `hostName`: Host name which you can get with the [list of hosts in the cluster](#list-hosts).
        * `updateMask`: Comma-separated string of settings to update.

            Here, we only specified a single setting, `assignPublicIp`.

        * `assignPublicIp`: Internet access to the host via a public IP address, `true` or `false`.

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

    1. View the [server response](../api-ref/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService.UpdateHosts](../api-ref/grpc/Cluster/updateHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        {% note 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_mask` parameter as an array of `paths[]` strings.
        
        {% cut "Format for listing settings" %}
        
        ```yaml
        "update_mask": {
            "paths": [
                "<setting_1>",
                "<setting_2>",
                ...
                "<setting_N>"
            ]
        }
        ```
        
        {% endcut %}
        
        {% endnote %}

        ```bash
        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>",
                    "update_host_specs": [
                    {
                        "host_name": "<host_name>",
                        "update_mask": {
                            "paths": [
                                "assign_public_ip"
                            ]
                        },
                        "assign_public_ip": <public_access_to_host>
                    }]
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.clickhouse.v1.ClusterService.UpdateHosts
        ```

        Where `update_host_specs[]` is the list of hosts and their parameters to update. Below is the structure of an individual element:

        * `host_name`: Host name which you can get with the [list of hosts in the cluster](#list-hosts).
        * `update_mask`: List of settings you want to update as an array of strings (`paths[]`).

            Here, we only specified a single setting, `assign_public_ip`.

        * `assign_public_ip`: Internet access to the host via a public IP address, `true` or `false`.

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

    1. View the [server response](../api-ref/grpc/Cluster/updateHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}


{% note warning %}

If you cannot [connect](connect/clients.md) to the host after the update, check that the cluster [security group](../concepts/network.md#security-groups) is properly configured for the host subnet.

{% endnote %}



## Restarting a host {#restart}

# Restarting a host

You may need to restart hosts to promptly address such issues as:

* Resource overutilization
* Memory leak
* Request deadlock
* Unresponsive ClickHouse® operations and internal processes

{% list tabs group=instructions %}

- Management console {#console}

  To restart a single host:

    1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
    1. Navigate to **Managed Service for&nbsp;ClickHouse**.
    1. Click the cluster name and navigate to the **Hosts** tab.
    1. In the host row, click ![icon](../../_assets/console-icons/ellipsis.svg) and select **Restart**.
    1. In the window that opens, enable **I am restarting host** and click **Confirm**.

  To restart multiple hosts in one go:

    1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
    1. Navigate to **Managed Service for&nbsp;ClickHouse**.
    1. Click the cluster name and navigate to the **Hosts** tab.
    1. Select the hosts you want to restart and click **Restart** at the bottom of the screen.
    1. In the window that opens, click **Confirm**.

- 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 restart one or multiple hosts, run the command below providing their names. Use the space character as a separator.

  Here is the command to restart a single host:

  ```bash
  yc managed-clickhouse host restart <host_name> \
     --cluster-name=<cluster_name>
  ```

  You can get the host name with the list of cluster hosts, and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.RestartHosts](../api-ref/Cluster/restartHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:

        ```bash
        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>/hosts:restartHosts' \
            --data '{
                      "hostNames": [
                        <list_of_host_names>
                      ]
                    }'
        ```

        Where `hostNames` is an array of strings. Each string is the name of the host to restart. You can get the host names with the [list of hosts in the cluster](hosts.md#list-hosts).

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

    1. View the [server response](../api-ref/Cluster/restartHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService.RestartHosts](../api-ref/grpc/Cluster/restartHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        ```bash
        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>",
                    "host_names": [
                      <list_of_host_names>
                    ]
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.clickhouse.v1.ClusterService.RestartHosts
        ```

        Where `host_names` is an array of strings. Each string is the name of the host to restart. You can get the host names with the [list of hosts in the cluster](hosts.md#list-hosts).

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

    1. View the [server response](../api-ref/grpc/Cluster/create.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Deleting a host {#remove-host}

{% note warning %}

You cannot delete a host from a cluster or shard if the [relevant limit for the minimum number of hosts](../concepts/limits.md#mch-limits) was reached.

You cannot delete hosts running [ClickHouse® Keeper](../concepts/replication.md#ck) if you enabled this replication option when creating the cluster.

You cannot delete hosts of different types (ClickHouse® and ZooKeeper) at the same time.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  To delete a single host:

    1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
    1. Navigate to **Managed Service for&nbsp;ClickHouse**.
    1. Click the cluster name and navigate to the **Hosts** tab.
    1. Click ![image](../../_assets/console-icons/ellipsis.svg) in the host row and select **Delete**.
    1. In the window that opens, enable **Delete host** and click **Confirm**.

  To delete multiple hosts in one go:

    1. In the [management console](https://console.yandex.cloud), select the folder containing the cluster.
    1. Navigate to **Managed Service for&nbsp;ClickHouse**.
    1. Click the cluster name and navigate to the **Hosts** tab.
    1. Select the hosts you want to delete and click **Delete** at the bottom of the screen.
    1. In the window that opens, click **Delete**.

- 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 one or multiple hosts from a cluster, run the command below, providing the names of the hosts you want to delete. Use the space character as a separator.

  The command for deleting a single host is as follows:

  ```bash
  yc managed-clickhouse hosts delete --cluster-name=<cluster_name> \
    <host_name>
  ```

  You can get the host names with the [list of cluster hosts](#list-hosts), and the cluster name, with the [list of clusters in the folder](cluster-list.md#list-clusters).


- Terraform {#tf}

  1. Open the current Terraform configuration file with the infrastructure plan.

     For more on how to create such a file, see the [Creating a cluster](cluster-create.md) section.
  
  1. Delete one or multiple `CLICKHOUSE` hosts from the `hosts` section.
  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Type `yes` and press **Enter**.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If 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.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

  For more information, see [this Terraform provider guide](../../terraform/resources/mdb_clickhouse_cluster.md).

  {% note warning "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.
  
  {% cut "How to change these limits" %}
  
  Add the `timeouts` section to your cluster description, such as the following:
  
  ```hcl
  resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
    ...
    timeouts = {
      create = "1h30m" # 1 hour 30 minutes
      update = "2h"    # 2 hours
      delete = "30m"   # 30 minutes
    }
  }
  ```
  
  {% endcut %}
  
  {% endnote %}


- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it in an environment variable:
    
        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```
    
    1. Call the [Cluster.DeleteHosts](../api-ref/Cluster/deleteHosts.md) method, e.g., via the following [cURL](https://curl.se/) request:
    
        ```bash
        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>/hosts:batchDelete' \
            --data '{
                      "hostNames": [
                        <list_of_host_names>
                      ]
                    }'
        ```
    
        Where `hostNames` is an array of strings. Each string is the name of a host to delete. You can get the host names with the [list of hosts in the cluster](#list-hosts).
    
        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).
    
    1. View the [server response](../api-ref/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it in an environment variable:
    
        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```
    
    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.
    
    1. Call the [ClusterService.DeleteHosts](../api-ref/grpc/Cluster/deleteHosts.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:
    
        ```bash
        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>",
                    "host_names": [
                      <list_of_host_names>
                    ]
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.clickhouse.v1.ClusterService.DeleteHosts
        ```
    
        Where `host_names` is an array of strings. Each string is the name of a host to delete. You can get the host names with the [list of hosts in the cluster](#list-hosts).
    
        You can get the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).
    
    1. View the [server response](../api-ref/grpc/Cluster/deleteHosts.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

_ClickHouse® is a registered trademark of [ClickHouse, Inc](https://clickhouse.com)._