冷热数据分离列存
 
                  更新时间 2025-02-05 09:37:13
                 
 
                    最近更新时间: 2025-02-05 09:37:13
                  
 本页介绍天翼云TeleDB数据库冷热数据分离列存。
 创建列存分区表
CREATE TABLE tp (
    id         int not null,
    a          int not null
) PARTITION BY RANGE (a);
-- 创建分区
CREATE TABLE tp_20 PARTITION OF tp
    FOR VALUES FROM (10) TO (20) using pax;   
CREATE TABLE tp_30 PARTITION OF tp
    FOR VALUES FROM (20) TO (30) using pax;
insert into tp values (1, 10);
insert into tp values (2, 10);
insert into tp values (3, 10);
insert into tp values (4, 10);
insert into tp values (5, 10);
insert into tp values (6, 10);
insert into tp values (7, 10);
insert into tp values (8, 10);
insert into tp values (9, 10);
insert into tp values (10, 10);
insert into tp values (11, 10);
insert into tp values (12, 10);
insert into tp values (13, 10);
insert into tp values (14, 10);
insert into tp values (15, 10);
insert into tp values (16, 10);
insert into tp values (17, 10);
insert into tp values (18, 10);
insert into tp values (19, 20);
insert into tp values (20, 20);
insert into tp values (21, 20);
insert into tp values (22, 20);
insert into tp values (23, 20);
insert into tp values (24, 20);
例如,pax的数据目录在dn01节点的pg_data/data/dn01/base/13422/238312_pax/中。
热转冷
ALTER TABLE tp
    alter_partition partition tp_20  
    SET storage_type oss OPTIONs (server 'minio_foreign_server', filePath '/bucket_name/tp1',enableCache 'true');
- tp:分区主表的名字。
- tp_20:分区子表的名字。
- oss:使用对象存储存储数据。
- sever:创建的server服务器的名字。
- filePath:数据存在对象存储的路径。
- enableCache:是否使用缓存,true或false。
热转冷后数据可读:
teledb=# select * from tp order by id;
 id | a  
----+----
  1 | 10
  2 | 10
  3 | 10
  4 | 10
  5 | 10
  6 | 10
  7 | 10
  8 | 10
  9 | 10
 10 | 10
 11 | 10
 12 | 10
 13 | 10
 14 | 10
 15 | 10
 16 | 10
 17 | 10
 18 | 10
 19 | 20
 20 | 20
 21 | 20
 22 | 20
 23 | 20
 24 | 20
(24 rows)
冷分区不可写:
teledb=# insert into tp values (1, 10);
ERROR:  ParquetDmlInit failed: Data cannot be written to tp_20's remote cold storage.
冷转热
ALTER TABLE tp
    alter_partition partition tp_20  
    SET storage_type local;
- tp:分区主表的名字。
- tp_20:分区子表的名字。
- local:数据存放在本地。
此时分区可读可写:
teledb=# select * from tp order by id;
 id | a  
----+----
  1 | 10
  2 | 10
  3 | 10
  4 | 10
  5 | 10
  6 | 10
  7 | 10
  8 | 10
  9 | 10
 10 | 10
 11 | 10
 12 | 10
 13 | 10
 14 | 10
 15 | 10
 16 | 10
 17 | 10
 18 | 10
 19 | 20
 20 | 20
 21 | 20
 22 | 20
 23 | 20
 24 | 20
(24 rows)
teledb=# insert into tp values (1, 10);
INSERT 0 1
