Create replicated tables in your Managed ClickHouse® cluster
Managed Service for ClickHouse® uses the
ReplicatedMergeTree
To enable replication,
create tables on each host separately or use a distributed
DDL query
Create a replicated table on all cluster hosts
To create a replicated table on all hosts in your cluster, use a distributed DDL query, as in the following example:
CREATE TABLE my_db.my_db_table ON CLUSTER '{cluster}' (
log_date Date,
user_name String
)
ENGINE = ReplicatedMergeTree()
PARTITION BY log_date
ORDER BY (log_date, user_name);
-
my_db
: Database name -
my_db_table
: Name of the replicated table within the database -
{cluster}
: Managed ClickHouse® cluster ID macro
To learn more about managing interactions between replicated and distributed tables in your Managed ClickHouse® cluster, refer to Sharding.
Create a replicated table on a specific cluster host
To create a ReplicatedMergeTree table on a specific ClickHouse® host, use the following example:
CREATE TABLE my_db.my_db_table ON CLUSTER '{cluster}' (
log_date Date,
user_name String
)
ENGINE = ReplicatedMergeTree('/my_db_table', '{replica}')
PARTITION BY log_date
ORDER BY (log_date, user_name);
-
my_db
: Database name -
my_db_table
: Name of the replicated table within the database -
{cluster}
: Managed ClickHouse® cluster ID macro -
/my_db_table
: Path to the table in ClickHouse Keeper. Make sure it starts with/
-
{replica}
: Host ID macro
For more information on the query structure, refer to
ClickHouse® documentation