openGauss 每日一练第 8 天打卡,我来了!又可以学习,真开心~

学习

今天第 8 课,学习 openGauss 分区表!

分区表是把逻辑上的一张表根据某种方案分成几张物理块进行存储,这张逻辑上的表称之为分区表,物理块称之为分区。

分区表是一张逻辑表,不存储数据,数据实际是存储在分区上的。

课后作业打卡

1.创建一个含有5个分区的范围分区表store,在每个分区中插入记录

1
2
3
4
5
6
7
8
9
10
11
12
13
create table store
(
id int,
name CHAR(20)
)
partition by range (id)
(
partition store_p0 values less than (50),
partition store_p1 values less than (100),
partition store_p2 values less than (150),
partition store_p3 values less than (200),
partition store_p4 values less than (250)
);

2.查看分区1上的数据

1
2
3
4
5
insert into store values (1,'a'),(51,'b'),(101,'c'),(151,'d'),(201,'e');
insert into store values (300,'f');
select * from store;
select * from store partition(store_p1);
select * from store partition(store_p3);

3.重命名分区2

1
alter table store rename partition store_p2 to store_lucifer2;

4.删除分区5

1
alter table store drop partition store_p4;

5.增加分区6

1
alter table store add partition store_p5;

6.在系统表pg_partition中查看分区信息

1
select * from pg_partition;

7.删除分区表

1
drop table store;

写在最后

今天的作业打卡结束!🎉