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

# Managing ClickHouse® Keeper hosts

When managing ClickHouse® Keeper hosts, you can do the following:

* [Get a list of hosts](#list-hosts).
* [Create a host](#add-ck).
* [Change ClickHouse® Keeper settings](#update-keeper-settings).
* [Restart a host](#restart-host).
* [Convert non-replicated tables to replicated ones](#replicated-tables).
* [Delete a ClickHouse® Keeper host](#delete-host).

For more information about ClickHouse® Keeper hosts, see [ClickHouse® Keeper](../concepts/coordination-system.md#ck).

## 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 ClickHouse® Keeper host {#add-ck}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), navigate to the folder dashboard and select **Managed Service for&nbsp;ClickHouse**.
  1. Click the cluster name and navigate to the **Hosts** tab.
  1. Click **Create ClickHouse Keeper host** in the top-right corner of the page.
  1. Select the [availability zone](../../overview/concepts/geo-scope.md) and a subnet inside it.
  1. Click **Save**.

{% endlist %}

## Changing ClickHouse® Keeper settings {#update-keeper-settings}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), navigate to the folder dashboard and select **Managed Service for&nbsp;ClickHouse**.
  1. Select the cluster and click **Edit** in the top panel.
  1. Under **Clickhouse Keeper host class**, select the platform, VM type, and required ClickHouse® Keeper host class.
  1. Under **ClickHouse Keeper storage size**, specify the disk type and storage size, and set up [automatic storage size increase](../concepts/storage.md#autoscaling).
  1. Click **Save changes**.

{% endlist %}

## Restarting a host {#restart-host}

# 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 %}

## Converting non-replicated tables to replicated ones {#replicated-tables}

You can convert MergeTree-based non-replicated tables to ReplicatedMergeTree-based [replicated](../concepts/replication.md#replicated-tables) ones:

* Automatically, when the coordination service gets activated.
* Using SQL, after the coordination service gets activated.

For more on table engines, see [this ClickHouse® guide](https://clickhouse.com/docs/enen/engines/table-engines/mergetree-family). 

{% list tabs group=instructions %}

- Automatically {#auto}

  To automatically convert non-replicated tables to replicated ones, enable table conversion when [activating the coordination service](update.md#enable-coordination).

- SQL {#sql}

  To convert a non-replicated table to a replicated one:

  1. Make the table unusable:
    
      ```sql
      DETACH TABLE <table_name>;
      ```

  1. Convert the table to a replicated one:

      ```sql
      ATTACH TABLE <table_name> AS REPLICATED;
      ```

  1. Restore and synchronize the state of your table replica in ClickHouse® Keeper:

      ```sql
      SYSTEM RESTORE REPLICA <table_name>;
      ```

{% endlist %}

## Deleting a ClickHouse® Keeper host {#delete-host}

{% note warning %}

You can delete only one ClickHouse® Keeper host at a time. However, there must be at least three ClickHouse® Keeper hosts left in the cluster at all times.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

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

- 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 ClickHouse® Keeper host:

  1. See the description of the CLI command for deleting a host:
    
      ```bash
      yc managed-clickhouse hosts delete --help
      ```
      
  1. Delete the host by running this command:

      ```bash
      yc managed-clickhouse hosts delete <host_name> \ 
        --cluster-id=<cluster_ID>
      ```

      You can get the host name with the [list of hosts](#list-hosts) in the cluster.

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

- 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.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": [
            <host_name>
          ]
        }'
      ```
  
      You can get the host name with the [list of hosts](#list-hosts) in the cluster.

      You can get the cluster ID with the [list of clusters](cluster-list.md#list-clusters) in the folder.
  
  1. Check 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 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.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": [
            <host_name>
          ]
        }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.clickhouse.v1.ClusterService.DeleteHosts
      ```
  
      You can get the host name with the [list of hosts](#list-hosts) in the cluster.

      You can get the cluster ID with the [list of clusters](cluster-list.md#list-clusters) in the folder.
  
  1. Check 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)._