Create replicated tables in your Managed ClickHouse® cluster

Managed Service for ClickHouse® uses ReplicatedMergeTree engine to replicate tables on your cluster.

To enable replication, create tables on each host separately or use a distributed DDL query to create them on all cluster hosts.

Create a replicated table on a specific cluster host

To create a ReplicatedMergeTree table on a specific ClickHouse® host, send the following query:

CREATE TABLE my_db.my_db_table ON CLUSTER default (
   log_date Date, 
   user_name String
)
ENGINE = ReplicatedMergeTree('/my_db_table', '{replica}') 
PARTITION BY log_date 
ORDER BY (log_date, user_name);

Let's look through this query in detail:

  • my_db is the name of your database.
  • my_db_table is the name of the replicated table within the database.
  • /my_db_table is the path to the table in ClickHouse Keeper. Make sure it starts with /.
  • {replica} is your host ID macro.

For more information on the query structure, see ClickHouse® documentation .

Create a replicated table on all cluster hosts

Use a distributed DDL request to create replicated tables on all hosts within your cluster:

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);

Let's look through this query in detail:

  • my_db is the name of your database.
  • my_db_table is the name of the replicated table within the database.
  • {cluster} will automatically acquire your Managed ClickHouse® cluster ID.

See Sharding for more information on how to manage interaction between replicated and distributed tables in your Managed ClickHouse® cluster.

See also