分布式复制表实践

创建复制表

use replic_db;
CREATE TABLE retest on cluster cluster_2shards_2replicas(
    x UInt32
) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/{database}/retest', '{replica}') 
ORDER BY x;

创建分布式表

use replic_db;
CREATE TABLE   retest_all_1  
on cluster cluster_2shards_2replicas AS replic_db.retest ENGINE = Distributed(cluster_2shards_2replicas, replic_db, retest, rand());

添加默认的zk路径

vim /etc/clickhouse-server/conf/config.xml
/clickhouse/tables/{shard}/{database}/{table}
{replica}

在创建ReplicatedMergeTree 不需要指定参数

CREATE TABLE retest_def on cluster cluster_2shards_2replicas(
x UInt32
) ENGINE = ReplicatedMergeTree
ORDER BY x;

CREATE TABLE gl_test.events on cluster cluster_2shards_2replicas
(
    `event` String,
    `distinct_id` String,
    `time` DateTime,
    `pagetitle` String,
    `pagecontroller` String,
    `http_referer` String,
    `keyword` String,
    `latest_scene` String,
    `scene` String,
    `productdbpid` String,
    `url_path` String
)
ENGINE = ReplicatedMergeTree
PARTITION BY toYYYYMMDD(time)
ORDER BY time

CREATE TABLE gl_test.events_all
on cluster cluster_2shards_2replicas
 AS gl_test.events 
ENGINE = Distributed('cluster_2shards_2replicas', 'gl_test', 'events', rand()) 

你可能感兴趣的:(分布式复制表实践)