冷熱數據分離列存
更新時間 2025-02-05 09:37:13
最近(jin)更(geng)新時間: 2025-02-05 09:37:13
分(fen)享(xiang)文章(zhang)
本頁介紹天翼云(yun)TeleDB數據(ju)庫冷熱數據(ju)分離列存(cun)。
創建列存分區表
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的數據目(mu)錄在dn01節(jie)點的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