Migrating data to Managed Service for ClickHouse® using ClickHouse®
With Data Transfer, you can transfer your database from a third-party ClickHouse® source cluster to a Managed Service for ClickHouse® target cluster.
This method allows you to:
- Copy the database without interrupting user service.
- Go without creating an intermediate VM or granting online access to your Managed Service for ClickHouse® target cluster.
You can also use this method to transfer data between two Managed Service for ClickHouse® clusters. For a successful transfer, specify the 8443
and 9440
ports in the source endpoint and add the SSL certificate.
For more information, see What tasks Yandex Data Transfer is used for.
Getting started
Allow connecting to the source cluster from the internet.
Transferring data
-
Prepare the infrastructure:
ManuallyUsing Terraform-
Create a Managed Service for ClickHouse® target cluster with the computing capacity and storage size appropriate for the environment where the copied database is deployed.
When creating a cluster, specify the security group prepared earlier.
The database name in the target cluster must be the same as the source database name.
If you are going to connect to the cluster via Yandex WebSQL, enable WebSQL access in the cluster settings.
-
-
Database type:
ClickHouse
-
Endpoint parameters → Connection settings:
On-premise
Specify the parameters for connecting to the source cluster.
-
-
-
Database type:
ClickHouse
-
Endpoint parameters → Connection settings:
Managed cluster
Select a target cluster from the list and specify its connection settings.
-
-
Create a transfer of the Snapshot type that will use the created endpoints and activate it.
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the data-transfer-ch-mch.tf
configuration file to the same working directory.This file describes:
- Network.
- Subnet.
- Security group and the rule required to connect to a cluster.
- Managed Service for ClickHouse® target cluster.
- Source endpoint.
- Target endpoint.
- Transfer.
-
Specify the following in the
data-transfer-ch-mch.tf
file:-
source_user
andsource_pwd
: Username and password to access the source.source_db_name
: Database name.source_host
: FQDN or IP address of the ClickHouse® server.source_shard
: Shard name.source_http_port
andsource_native_port
: HTTP and ClickHouse® native interface connection ports.
-
Target cluster parameters also used as target endpoint parameters:
target_clickhouse_version
: ClickHouse® version.target_user
andtarget_password
: Name and user password of the database owner.
-
Yandex Cloud CLI parameters to activate the cluster automatically:
-
profile_name
: Name of your Yandex Cloud CLI profile.If you do not have the Yandex Cloud command line interface yet, install and initialize it.
-
-
-
(Optional) If you are going to connect to the cluster via Yandex WebSQL, add the
access
section to the cluster resource:access { web_sql = true }
-
Check that the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
.Once created, your transfer will be activated automatically.
-
Test the transfer
-
Wait for the transfer status to change to Completed.
-
Make sure the data from the source ClickHouse® cluster has been moved to the Managed Service for ClickHouse® database:
Yandex WebSQLCLI-
Create a connection to the Managed Service for ClickHouse® cluster database.
-
Make sure the DB contains the tables from the source cluster. To do this, run this query to the database via the connection you created:
SHOW TABLES FROM <DB_name>;
-
Make sure the tables contain data from the source cluster tables. To do this, run this query to the table via the connection you created:
SELECT * FROM <DB_name>.<table_name>;
-
Get an SSL certificate to connect to the Managed Service for ClickHouse® cluster.
-
Connect to the database in the Managed Service for ClickHouse® cluster using
clickhouse-client
. -
Make sure the DB contains the tables from the source cluster:
SHOW TABLES FROM <DB_name>;
-
Make sure the tables contain data from the source cluster tables:
SELECT * FROM <DB_name>.<table_name>;
-
Delete the resources you created
Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need:
- Delete the Managed Service for ClickHouse® cluster.
- Delete the completed transfer.
- Delete endpoints for both the source and target.
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy
-
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-