学习目标
学习openGauss分区表索引
1.创建范围分区表products, 为表创建分区表索引1,不指定索引分区的名称,创建分区表索引2,并指定索引分区的名称,创建GLOBAL分区索引3
–创建表空间
CREATE TABLESPACE tbs_01 RELATIVE LOCATION 'tablespace1/tbs_01'; CREATE TABLESPACE tbs_02 RELATIVE LOCATION 'tablespace2/tbs_02'; CREATE TABLESPACE tbs_03 RELATIVE LOCATION 'tablespace3/tbs_03'; CREATE TABLESPACE tbs_04 RELATIVE LOCATION 'tablespace3/tbs_04';
复制
–创建范围分区表products
create schema lp; CREATE TABLE su.products ( product_id integer, product_name char(20), category_id char(10) ) PARTITION BY RANGE(product_id) ( PARTITION p1 VALUES LESS THAN (100), PARTITION p2 VALUES LESS THAN (200) TABLESPACE tbs_01, PARTITION p3 VALUES LESS THAN (MAXVALUE) TABLESPACE tbs_02 );
复制
–为表创建分区表索引1,不指定索引分区的名称
CREATE INDEX su.products_index1 ON su.products(category_id) LOCAL;
复制
–创建分区表索引2,并指定索引分区的名称
CREATE INDEX su.products_index2 ON su.products(product_name) LOCAL ( PARTITION product_p_index1, PARTITION product_p_index2 TABLESPACE tbs_03, PARTITION product_p_index3 TABLESPACE tbs_04 );
复制
–创建GLOBAL分区索引3
CREATE INDEX su.products_index3 ON su.products(product_id) GLOBAL; CREATE INDEX su.products_index3 ON su.products(product_id) ; --不带global声明
复制
–查看表
\d+ su.products;
复制
2.在分区表索引1上,修改分区表索引的表空间,重命名分区表索引
alter index su.products_index1 set tablespace tbs_03;
复制
注:不能直接修改索引表空间,只能move分区索引
ALTER INDEX su.products_index1 MOVE PARTITION p1_product_id_idx TABLESPACE tbs_03; ALTER INDEX su.products_index1 RENAME PARTITION p1_product_id_idx TO p1_product_id_idx111;
复制
3.在分区表索引2上,重建单个索引分区和分区上的所有索引
reindex index su.products_index2 partition product_p_index1; reindex table su.products partition p1;
复制
注意:rename to后面不能带schema
4.使用\d+、系统视图pg_indexes和pg_partition查看索引信息
\d+ su.products; select * from pg_indexes where schemaname='lp' and tablename = 'products'; select * from pg_partition;
复制
5.删除索引、表和表空间
drop index su.products_index1; drop index su.products_index2; drop index su.products_index3; drop table su.products; drop tablespace tbs_01; drop tablespace tbs_02; drop tablespace tbs_03; drop tablespace tbs_04;
复制
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
2025年3月国产数据库大事记
墨天轮编辑部
600次阅读
2025-04-03 15:21:16
内蒙古公司成功完成新一代BOSS云原生系统割接上线
openGauss
199次阅读
2025-03-24 09:40:40
第4期 openGauss 中级认证OGCP直播班招生中!3月30日开课
墨天轮小教习
162次阅读
2025-03-17 15:48:40
openGauss 7.0.0-RC1 版本正式发布!
Gauss松鼠会
146次阅读
2025-04-01 12:27:03
openGauss 7.0.0-RC1 版本体验:一主一备快速安装指南
孙莹
127次阅读
2025-04-01 10:30:07
从数据库源码比较 PostgreSql和OpenGauss的启动过程
maozicb
85次阅读
2025-03-24 15:55:04
一文快速上手openGauss
进击的CJR
80次阅读
2025-03-26 16:12:54
openGauss HASH JOIN原理
lbsswhu
61次阅读
2025-03-18 10:45:01
openGauss 学习之路:集群部署实战探索
openGauss
55次阅读
2025-03-21 10:34:13
openGauss问题记录:开启备机归档且备机stop情况下,执行gs_probackup失败
zym
45次阅读
2025-03-18 19:06:13
目录