clickhouse集群
使用笔记
/*集群名在安装时定义,在这里查询*/ select * from system.clusters; /*创建分布式库*/ create database bigdata_user on cluster cluster_3s_2r; use bigdata_user; /*创建本地表,会在每个节点创建一个本地表*/ create table user_local on cluster cluster_3s_2r( start_time DateTime, username String, user_agent String, user_ip String, visit_url String ) ENGINE = MergeTree() PARTITION BY toYYYYMMDD(start_time) order by start_time; /*下面这个insert只会在本节点插入数据,其它节点不会有数据*/ insert into user_local values('2023-01-01','name','agent','ip','url'); /*创建集群表*/ create table ods_visit_user on cluster cluster_3s_2r( start_time DateTime, username String, user_agent String, user_ip String, visit_url String ) ENGINE = Distributed(cluster_3s_2r, 'bigdata_user', user_local, rand()); /*集群表的truncate不管用,delete不管用,insert能用,时间也不对。*/ /*可删除集群表,本地表数据不受影响*/ /*分布式表引擎不支持mutations的问题。mutations是指对已有数据的修改操作,而分布式表引擎通常用于支持大量数据的读取和查询,但不支持修改操作。*/ TRUNCATE table ods_visit_user; delete from ods_visit_user; drop table IF EXISTS bigdata_user.ods_visit_user ON CLUSTER cluster_3s_2r; delete from user_local; /*insert到集群表,不会实时插入,配置insert_distributed_sync=true以实时插入*/ insert into ods_visit_user values('2023-01-01 11:11:11','name','agent','ip','url');
相关阅读
评论:
↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑