暂无图片
TBase分布式数据的冷热数据分离表的使用方法?求详解
我来答
分享
向前
2021-01-12
TBase分布式数据的冷热数据分离表的使用方法?求详解
TBase分布式数据的冷热数据分离表的使用方法?求详解
我来答
添加附件
收藏
分享
问题补充
1条回答
默认
最新
向前

TBase分布式数据库支持不同粒度的时间分区表,我们可以通过设置不同的节点组,同时将节点组中的节点设置为热节点(默认)或者冷节点,那么热节点数据可以采用高性能存储设备比如SSD盘,那么冷节点数据可以采用普通的sata盘来存放历史,不常使用或者访问的历史数据,这里我就举几个TBase冷热分离的使用过程中的几个典型错误。
TBase冷热数据分离,前提需要创建的表必须为时间范围分区表,要求时间列必须包含在shardkey中,如果有订阅发布需求的话,必须有主键约束,而且我们已经创建好了冷热节点组。

标准语句1:
create table ttt(id int ,name varchar(20),time1 timestamp ,primary key(id,time1))
partition by range(time1) begin (timestamp without time zone ‘2020-01-01’) step (interval ‘1 year’) partitions(3) distribute by shard(id,time1) to group g1 g2;

g1为默认的热节点组,g2为冷节点组。当前实例默认的冷热分离粒度以年为单位。

错误1:ERROR: cold-hot table partitioned by year should begin with timestamp ‘yy:01:01 00:00:00’
创建语句1:create table t1_year(id int ,name varchar(20),time1 timestamp ,primary key(id,time1))
partition by range(time1) begin (timestamp without time zone ‘2020-12-31’) step (interval ‘1 year’) partitions(3) distribute by shard(id,time1) to group g1 g2;

原因1:(timestamp without time zone ‘2020-12-31’) 粒度为年时,日期需要满足 xxxx-01-01的日期,否则报错如下:

修改为:create table t1_year(id int ,name varchar(20),time1 timestamp ,primary key(id,time1))
partition by range(time1) begin (timestamp without time zone ‘2020-01-01’) step (interval ‘1 year’) partitions(3) distribute by shard(id,time1) to group g1 g2;

错误2:ERROR: cold-hot table shoule partition by year
语句2:
create table t4_year_nopk(id int ,name varchar(20),time1 timestamp ,primary key(id))
partition by range(time1) begin (timestamp without time zone ‘2020-01-01’) step (interval ‘1 month’) partitions(3) distribute by shard(id,time1) to group g1 g2;

原因2:postgres=# show cold_hot_sepration_mode ; 粒度为年,但创建表时,interval使用的是“month”月粒度,所以报错。
cold_hot_sepration_mode

year
(1 row)
修改为:create table t4_year_nopk(id int ,name varchar(20),time1 timestamp ,primary key(id))
partition by range(time1) begin (timestamp without time zone ‘2020-01-01’) step (interval ‘1 year’) partitions(3) distribute by shard(id,time1) to group g1 g2;

错误3:ERROR: cold group 16741 conflict exist table hot group 16741
原因3:将已经存在表数据的某个DN设置为节点组的冷节点时,创建时间冷热分区表时报错,需要将原表删除。
语句3:create table t4_year_nopk(id int ,name varchar(20),time1 timestamp ,primary key(id))
partition by range(time1) begin (timestamp without time zone ‘2020-01-01’) step (interval ‘1 year’) partitions(3) distribute by shard(id,time1) to group g1 g2;

TBase支持冷热节点组的设置。如g1组(dn001,dn002)均为热节点 ,g2(dn003 )将dn003设置为冷节点后,后续添加dn004到g2组中,dn004自动成为冷节点。

错误4: ERROR: node:dn002, backend_pid:3447, nodename:dn002,backend_pid:3447,message:value to inserted execeed range of partitioned table
原因4: insert into t5_year_nopk values(3,‘ccc’,‘2023-12-12’); 插入的数据超出定义从2020-01-01开始到2022-12-31的3个分区范围,有效范围为2020-01-01到2022-12-31,
大于或小于这个范围均会报错。
语句4:create table t4_year_nopk(id int ,name varchar(20),time1 timestamp ,primary key(id))
partition by range(time1) begin (timestamp without time zone ‘2020-01-01’) step (interval ‘1 year’) partitions(3) distribute by shard(id,time1) to group g1 g2;

错误5:ERROR: node:dn004, backend_pid:12930, nodename:dn004,backend_pid:12930,message:node dn004 is hot node, can’t use it to store cold data
原因5:TBase在设置冷节点组时,如g2(dn003,dn004 )存在两个节点,只针对将dn003设置为冷节点,后续dn004未设置为冷节点。需要连接dn004 使用select pg_stat_node_access();
确认状态,如果状态为hot,需要使用postgres=# select pg_set_node_cold_access();将其设置为冷节点,如果后续想取消冷节点可以使用select pg_clear_node_cold_access();取消。

注意:需要连接dn数据节点做如下操作,连接CN协调节点做设置无意义,且不生效。
postgres=# select pg_set_node_cold_access();
pg_set_node_cold_access

success
(1 row)

postgres=#
postgres=#
postgres=# select pg_clear_node_cold_access();
pg_clear_node_cold_access

success
(1 row)

postgres=# select pg_stat_node_access();
pg_stat_node_access

(hot)
(1 row)

postgres=#

postgres=# select *from t1_year order by 1;
id | name | time1
----±-------±--------------------
10 | 你 | 2020-10-10 00:00:00
11 | 你hao | 2020-12-10 00:00:00
12 | 哈哈 | 2021-12-10 00:00:00
13 | \x1B[C | 2021-12-10 00:00:00
(4 rows)

postgres=#
postgres=# execute direct on (dn001) ‘select *from t1_year’;
id | name | time1
----±-------±--------------------
12 | 哈哈 | 2021-12-10 00:00:00
13 | \x1B[C | 2021-12-10 00:00:00
(2 rows)

postgres=# execute direct on (dn002) ‘select *from t1_year’;
id | name | time1
----±-----±------
(0 rows)

postgres=# execute direct on (dn003) ‘select *from t1_year’;
id | name | time1
----±------±--------------------
10 | 你 | 2020-10-10 00:00:00
11 | 你hao | 2020-12-10 00:00:00
(2 rows)

postgres=# execute direct on (dn004) ‘select *from t1_year’;
id | name | time1
----±-----±------
(0 rows)

暂无图片 评论
暂无图片 有用 0
打赏 0
回答交流
Markdown


请输入正文
提交