Replication ClickHouse
Managed Service for ClickHouse helps enable replication for ClickHouse clusters consisting of 2 or more hosts by using Apache ZooKeeper. You just need to create tables of the required type. ZooKeeper hosts will be created and configured automatically.
Note
If you created a ClickHouse cluster with two or more hosts, you can't reduce the number of hosts to one.
Due to limited resources, the b1.nano, b1.micro, b2.nano, and b2.micro class hosts are not replicated.
Replicated tables
ClickHouse only supports automatic replication for ReplicatedMergeTree
tables (see Data replication in the ClickHouse documentation). To enable replication, you can create the tables on each host separately or use a distributed DDL query.
To create a ReplicatedMergeTree
table on a specific ClickHouse host, send the following query:
CREATE TABLE db_01.table_01 (log_date Date, user_name String) \
ENGINE = ReplicatedMergeTree('/table_01', '{replica}') PARTITION BY log_date ORDER BY (log_date, user_name);
Where:
-
db_01
is the DB name. -
table_01
is the table name. -
/table_01
is the path to the table in ZooKeeper, which must start with a forward slash/
. -
{replica}
is the host ID macro.
To create replicated tables on every host in the cluster, send a distributed DDL query (as described in the ClickHouse documentation):
CREATE TABLE db_01.table_01 ON CLUSTER '{cluster}' (log_date Date, user_name String) \
ENGINE = ReplicatedMergeTree('/table_01', '{replica}') PARTITION BY log_date ORDER BY (log_date, user_name);
The '{cluster}'
argument is automatically resolved to the ClickHouse cluster ID.
ZooKeeper hosts
For each ClickHouse cluster consisting of 2 or more hosts, Managed Service for ClickHouse creates a cluster of 3 ZooKeeper hosts. ZooKeeper hosts are taken into account when calculating resource consumption and the cost of the cluster.
How ZooKeeper hosts are managed:
-
By default, ZooKeeper hosts are created with a minimal host class. You can specify the necessary host class when creating a cluster via the API.
-
Managed Service for ClickHouse does not enable you to connect to ZopKeeper servers and configure them. However, you can change the resources allocated to ZooKeeper hosts by changing the host class.
-
If you didn't specify any subnets for the ZooKeeper hosts, Managed Service for ClickHouse automatically distributes them among the subnets of the network that the ClickHouse cluster is connected to.
For more information about using ZooKeeper to manage replication in ClickHouse, see the ClickHouse documentation.