You need to enable JavaScript to run this app.
文档中心
云数据库 veDB MySQL 版

云数据库 veDB MySQL 版

复制全文
下载 pdf
冷热分离
手动归档冷数据
复制全文
下载 pdf
手动归档冷数据
本文介绍如何手动归档冷数据,以及如何将冷数据再转换回热数据。​
前提条件​
  • 已连接 veDB MySQL 实例,操作详情请参见连接实例。​
使用限制​
  • 不支持对包含二级分区的分区表做冷热转换,关于分区表的更多限制,请参见冷热分离限制说明。​
  • 分区表仅支持通过设置子分区的 comment 来调整冷热属性,不支持设置表级别的冷热属性。​
  • 已经发起冷热转换的表,如果需要转换为新的类型,必须等待上一个转换任务完成。​
注意事项​
  • 归档后的冷表性能较差,建议提前测试归档后的数据能否满足业务需求。​
  • 归档后的冷表性能较差,若需要执行涉及冷表的 DDL 操作,请谨慎操作,避免 IO 异常。建议先将其转换为热表,待执行完 DDL 操作之后再转换为冷表,更多关于冷热分离功能下 DDL 操作的限制请参见冷热分离限制说明。​
归档冷数据​
veDB MySQL 通过新增 comment option 格式来进行冷热分离。无 comment option 的表默认为热表,通过 comment option 设置了表的冷热属性之后,不再支持删除 comment option,只允许修改冷热属性。​
冷热转换的关键字为:​
​
comment='storage_policy=[cold|hot]';​
​
关于 option 的设置说明,请参见下表:​
​
使用场景​
语法示例​
无 option 的表默认为热表​
​
create table a (a int) comment="user info";​
​
指定 option 创建冷表​
  • 创建普通冷表。​
  • ​
    create table t_cold (a int) comment="storage_policy=cold";​
    ​
  • 创建分区表,并指定对应分区的冷热属性。​
  • ​
    CREATE TABLE t_cold_part (​
    id int,​
    c datetime,​
    PRIMARY KEY (id, c)​
    )​
    PARTITION BY RANGE COLUMNS (c) (​
    PARTITION p0000 VALUES LESS THAN ('2021-01-01') comment="storage_policy=cold",​
    PARTITION p2021 VALUES LESS THAN ('2022-01-01') comment="storage_policy=hot",​
    PARTITION p9999 VALUES LESS THAN MAXVALUE​
    );​
    ​
修改一个没有 comment 的表​
  • 将某存量热表设置为冷表。​
  • ​
    alter table t_hot comment="storage_policy=cold";​
    ​
  • 将存量分区表的指定分区设置为冷分区。​
  • ​
    alter table t_cold_part set partition p2021 comment="storage_policy=cold";​
    ​
修改已存在 comment 的表​
  • 将冷热属性设置在后面(前面使用分号隔开)​
  • ​
    alter table t_hot comment="user comment, user info;storage_policy=cold";​
    ​
  • 把冷热属性设置在前面(后面使用分号隔开)​
  • ​
    alter table t_hot comment="storage_policy=cold;user comment, user info";​
    ​
  • 将冷热属性设置在中间(前后使用分号隔开)​
  • ​
    alter table t_hot comment="user comment;storage_policy=cold;user info";​
    ​
修改冷热属性外的其他 comment​
  • 在冷热属性前面设置(前面使用分号隔开)​
  • ​
    alter table t_hot comment="new info, data;storage_policy=cold;user comment, user info";​
    ​
  • 在冷热属性后面设置(后面使用分号隔开)​
  • ​
    alter table t_hot comment="storage_policy=cold;new info, data,user comment, user info";​
    ​
设置 option 后不允许删除,只能选择修改冷热属性​
  • 从普通表中的 comment 中去除已设置的冷热属性。​
  1. 原始表为 comment="storage_policy=cold;user info"​
  1. 执行 alter table a comment="user info"​
  1. 报错:Table disallow clear storage_policy from comment that had set storage_policy.​
  • 从分区表的 comment 中去除已设置的冷热属性。​
  1. 原始 partion p9999 为 comment="storage_policy=cold;user info"​
  1. alter table a set partition p9999 comment="user info"​
  1. 报错:Table disallow clear storage_policy from comment if partition had set storage_policy.​
​
将冷数据转换回热数据​
将归档的冷数据重新转换为热数据,即按照归档的方法,将表或分区的冷热属性设置为 hot 即可。​
  • 普通表​
  • ​
    alter table t_hot comment="storage_policy=hot";​
    ​
  • 分区表​
  • ​
    alter table t_cold_part set partition p0000 comment="storage_policy=hot";​
    ​
查询冷热转换进度​
可通过以下两种方式查询冷热转换进度。​
  • 方式一: 在 veDB MySQL 控制台的冷数据归档页签中,通过查看归档列表的状态列观察目标表的实际状态,操作步骤请参见查看冷数据归档信息。​
  • ​
    状态​
    说明​
    冷存数据​
    表示指定表或分区已经成功归档为冷数据。​
    热转冷中​
    表示正在进行热数据转冷中。​
    冷转热中​
    表示正在进行冷数据转热中。​
    说明​
    当在归档列表查询不到目标表时,表示冷数据转热数据任务已完成。​
    ​
  • 方式二:通过查看 information_schema.table_storage_options 表的 STORAGE_POLICY 列来观察指定表的实际状态。​
  • ​
    -- 普通表​
    select * from information_schema.table_storage_options where TABLE_NAME = "t_cold";​
    -- 分区表​
    select * from information_schema.table_storage_options where TABLE_NAME = "t_cold" and PARTITION_NAME = "p0000";​
    ​
  • ​
    STORAGE_POLICY​
    说明​
    stage_request_cold​
    表示指定表或分区,刚发起热数据转冷任务。​
    stage_convert_cold​
    表示存储已接收到任务,指定表或分区正在排队等待冷热转换。​
    stage_convert_cold:xx​
    表示正在进行热数据转冷中,并且完成了 xx%。​
    stage_request_hot​
    表示指定表或分区,刚发起冷数据转热任务。​
    stage_convert_hot​
    表示存储已接收到任务,指定表或分区正在排队等待冷热转换。​
    stage_convert_hot:xx​
    表示正在进行冷数据转热中,并且完成了 xx%。​
    cold​
    表示指定表或分区为冷表或冷分区。​
    说明​
    当表的状态由 hot 变为 cold,表示冷热转换已经完成。​
    hot​
    表示指定表或分区为热表或热分区。​
    说明​
    当表的状态由 cold 变为 hot,表示冷热转换已经完成。​
    ​
查询归档的冷数据大小​
可通过以下三种方式查询归档的冷数据大小。​
  • 方式一:在 veDB MySQL 控制台的冷数据归档页签中,可以查看冷数据总量以及具体表的数据量大小,操作步骤请参见查看冷数据归档信息。​
  • 方式二:通过 SQL 语句查看。​
  • ​
    -- 查询指定数据库的冷热数据大小​
    select if( options.STORAGE_POLICY like '%cold%', 'cold', 'hot' ) as type, ifnull(sum(data_length + index_length), 0) / 1024 / 1024 / 1024 'GB' from information_schema.partitions partitions left join information_schema.table_storage_options options on options.TABLE_SCHEMA = partitions.table_schema and options.TABLE_NAME = partitions.table_name and IF( ISNULL(options.PARTITION_NAME), '', options.PARTITION_NAME ) = IF( ISNULL(partitions.PARTITION_NAME), '', partitions.PARTITION_NAME ) where partitions.table_schema in ('database_name') and ( partitions.table_name not like '_%%\_gho' and partitions.table_name not like '_%%\_del' ) group by type;​
    -- 查询数据库容量信息​
    show ndb capacity​
    ​
  • 方式三:在 veDB MySQL 控制台的监控告警页签中的实例监控维度下,查看目标实例冷数据存储空间的实时总使用量,操作步骤请参见查看监控信息。​
​
最近更新时间:2026.08.21 11:56:50
这个页面对您有帮助吗?
有用
有用
无用
无用