分区表是把逻辑上的一张表根据某种方案分成几张物理块进行存储,这张逻辑上的表称之为分区表,物理块称之为分区。
分区表是一张逻辑表,不存储数据,数据实际是存储在分区上的。
0. 进入环境
su - omm gsql -r
复制
1.创建一个含有5个分区的范围分区表store,在每个分区中插入记录
先看看默认有什么吧:
\d+;
复制
– 回显
List of relations Schema | Name | Type | Owner | Size | Storage | Description --------+------+-------+-------+---------+----------------------------------+------------- public | t1 | table | omm | 0 bytes | {orientation=row,compression=no} | public | t2 | table | omm | 0 bytes | {orientation=row,compression=no} | (2 rows)
复制
创建表store
create table store ( id int, goods varchar(20), inventory int ) partition by range (inventory) ( partition store_p0 values less than (100), partition store_p1 values less than (200), partition store_p2 values less than (300), partition store_p3 values less than (400), partition store_p4 values less than (500) ); \d+ store; select * from pg_partition;
复制
– 回显
Table "public.store" Column | Type | Modifiers | Storage | Stats target | Description -----------+-----------------------+-----------+----------+--------------+------------- id | integer | | plain | | goods | character varying(20) | | extended | | inventory | integer | | plain | | Range partition by(inventory) Number of partition: 5 (View pg_partition to check each partition range.) Has OIDs: no Options: orientation=row, compression=no
复制
插入数据并查看
insert into store values (101, 'box', 80), (102, 'toy', 180), (103, 'citrus',260), (104, 'apple', 350), (105, 'egg', 450); select * from store;
复制
– 回显
id | goods | inventory -----+--------+----------- 101 | box | 80 102 | toy | 180 103 | citrus | 260 104 | apple | 350 105 | egg | 450 (5 rows)
复制
2.查看分区1上的数据
select * from store partition(store_p0);
复制
– 回显
omm=# id | goods | inventory -----+-------+----------- 101 | box | 80 (1 row)
复制
3.重命名分区2
ALTER TABLE store RENAME PARTITION store_p1 to store_p10; select relname from pg_partition;
复制
– 回显
relname ----------- store store_p0 store_p2 store_p3 store_p4 store_p10 (6 rows)
复制
4.删除分区5
ALTER TABLE store drop PARTITION store_p4; select relname from pg_partition;
复制
– 回显
relname ----------- store store_p0 store_p2 store_p3 store_p10 (5 rows)
复制
5.增加分区6
ALTER TABLE store add partition store_p5 VALUES LESS THAN (1000); select relname from pg_partition;
复制
– 回显
relname ----------- store store_p0 store_p2 store_p3 store_p10 store_p5 (6 rows)
复制
6.在系统表pg_partition中查看分区信息
select * from pg_partition;
复制
– 回显
relname | parttype | parentid | rangenum | intervalnum | partstrategy | relfilenode | reltablespace | relpages | reltuples | relallvisible | reltoastrelid | reltoastidxid | indextblid | indisusable | reldeltarelid | reldeltaidx | relcudescrelid | relcudescidx | relfrozenxid | intspnum | partkey | intervaltablespace | interval | boundaries | transit | reloptions | relfrozenxid64 -----------+----------+----------+----------+-------------+--------------+-------------+---------------+----------+-----------+---------------+---------------+---------------+------------+-------------+---------------+-------------+----------------+--------------+--------------+----------+---------+--------------------+----------+------------+---------+---------------------------------------------------+---------------- store | r | 16425 | 0 | 0 | r | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 | 0 0 | 0 | 0 | 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 | 9351 | | | | | {100} | | {orientation | | 3 | | | | | {orientation =row,compression=no,wait_clean_gpi=n} | 0 store_p0 | p | 16425 | 0 | 0 | r | 16429 | store_p2 | p | 16425 | 0 | 0 | r | 16431 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 | 9351 --More--=row,compression=no} | 9351 | | | | | {300} | | {orientation =row,compression=no} | 9351 store_p3 | p | 16425 | 0 | 0 | r | 16432 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 | 9351 | | | | | {400} | | {orientation =row,compression=no} | 9351 store_p10 | p | 16425 | 0 | 0 | r | 16430 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 | 9351 | | | | | {200} | | {orientation =row,compression=no} | 9351 store_p5 | p | 16425 | 0 | 0 | r | 16434 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | t | 0 | 0 | 0 | 0 | 9357 | | | | | {1000} | | {orientation =row,compression=no} | 9357 (6 rows)
复制
7.删除分区表
drop table store; \d+ store;
复制
– 回显
Did not find any relation named "store".
复制
删除成功(完).
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
520次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
306次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
201次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
165次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
157次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
140次阅读
2025-04-30 16:39:58
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
94次阅读
2025-04-18 10:49:53
Postgresql数据库单个Page最多存储多少行数据
maozicb
85次阅读
2025-04-23 16:02:19
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
61次阅读
2025-04-17 10:41:47
RISC-V 首迎 openGauss 7.0.0-RC1 全量版适配!数据库核心功能完整落地开源架构
openGauss
48次阅读
2025-04-16 10:33:59