Migrating data to Yandex Managed Service for ClickHouse® using Yandex Data Transfer
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 enables you to:
- Copy the database without interrupting user service.
- Eliminate the need for an intermediate VM or public internet 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 listening ports 8443 and 9440 on the source endpoint and add an SSL certificate.
For more information, see Problems addressed by Yandex Data Transfer.
Getting started
Enable inbound internet connections to the source cluster.
Required paid resources
- Managed Service for ClickHouse® cluster: Use of computing resources allocated to hosts, storage and backup size (see Managed Service for ClickHouse® pricing).
- Public IP addresses if public access is enabled for cluster hosts (see Virtual Private Cloud pricing).
- Each transfer: Use of computing resources and number of transferred data rows (see Data Transfer pricing).
Transferring data
-
Set up the infrastructure:
ManuallyUsing Terraform-
Create a Managed Service for ClickHouse® target cluster with the computing and storage capacity matching the source database’s environment.
When creating a cluster, specify the security group you created earlier.
The source and target database names must be the same.
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 source cluster connection settings.
-
-
-
Database type:
ClickHouse. -
Endpoint parameters → Connection settings:
Managed cluster.Select your target cluster from the list and specify its connection settings.
-
-
Create a Snapshot-type transfer, configure it to use the previously created endpoints, then 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 for connecting to a cluster.
- Managed Service for ClickHouse® target cluster.
- Source endpoint.
- Target endpoint.
- Transfer.
-
In the
data-transfer-ch-mch.tffile, specify the following:-
source_userandsource_pwd: Username and password to access the source database.source_db_name: Database name.source_host: ClickHouse® server IP address or FQDN.source_shard: Shard name.source_http_portandsource_native_port: HTTP and ClickHouse® native interface ports.
-
Target cluster parameters used as target endpoint parameters:
target_clickhouse_version: ClickHouse® version.target_userandtarget_password: Database owner username and password.
-
Yandex Cloud CLI parameters for automating cluster activation:
-
profile_name: Yandex Cloud CLI profile name.If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
-
-
-
Optionally, to enable connections via Yandex WebSQL, add the
accesssection to the cluster resource:access { web_sql = true } -
Make sure the Terraform configuration files are correct using this command:
terraform validateTerraform will show any errors found in your configuration files.
-
Create the required infrastructure:
-
Run this command to view the planned 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.
-
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 your transfer
-
Wait for the transfer status to change to Completed.
-
Check that the data has been transferred from the source ClickHouse® cluster to the Managed Service for ClickHouse® database:
Yandex WebSQLCLI-
Create a connection to the database in the Managed Service for ClickHouse® cluster.
-
Check that the database contains all tables from the source cluster by running the following query via the connection you created:
SHOW TABLES FROM <DB_name>; -
Check that the tables contain the same data as the source cluster tables by running the following query against them:
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 via
clickhouse-client. -
Check that the database contains all tables from the source cluster:
SHOW TABLES FROM <DB_name>; -
Check that the tables contain the same data as the source cluster tables:
SELECT * FROM <DB_name>.<table_name>;
-
Delete the resources you created
Some resources are not free of charge. Delete the resources you no longer need to avoid paying for them:
-
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.
-