1.在集群的每个机器上面建立本地表
1)方式一:在集群每台机器上运行代码
CREATE TABLE st_center.st_pc_office_all_user_retention_v1
(
`apptypeid` String,
`qid` String,
`os` String,
`ver` String,
`type` String,
`user_type` String,
`install_day` UInt64,
`dau` UInt64,
`day1_dau` UInt64,
`day2_dau` UInt64,
`day3_dau` UInt64,
`dt` String
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/{table}', '{replica}')
PARTITION BY dt
ORDER BY (dt, qid, ver, os, type, user_type, apptypeid)
SETTINGS index_granularity = 8192;
2)方式二:一次性在集群每个机器上建立本地表
CREATE TABLE IF NOT EXISTS st_center.st_pc_office_all_user_retention_v1 ON CLUSTER default_cluster
(
...
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/{table}', '{replica}')
PARTITION BY dt
ORDER BY (dt, qid, ver, os, type, user_type, apptypeid)
SETTINGS index_granularity = 8192;
关键词:ON CLUSTER
- [1] /clickhouse/tables/是一般性前缀
- [2] {layer}-{shard}是分片识别符,同一个分片内的所有机器应该保持相同
- [3] /cl