【关注茅哥】分享技术,分享科技,如果觉得还可以别忘了关注茅哥、点个赞哦!若还有什么不明白的地方请评论区下方留言,若想了解更多相关知识,请关注茅哥,会持续更新内容,谢谢支持!
其实PostgreSQL、greenPlum、Apache HAWQ、oushuDB,这几个的的底层都是基础postgresql的语法,本片重点从其共性分区表的创建和分区表的一些常见操作进行分享。欢迎大家收藏转发。不用等到需要的时候再去到处查找了。
这里介绍常用的两种分区方式:list和range;
根据值的分组,相同的数据归类到一组,也就一个分区中;
create table gpsxmg.partition_list_test ( id int, name varchar(64), fdate varchar(10)) with (appendonly=true,orientation=parquet,compresstype=snappy)distributed randomlypartition by list (fdate) ( partition p1 values ('2017-01-01', '2017-01-02'), partition p2 values ('2017-01-03'), default partition pd);
根据分区字段的值范围区间来分区,每一个分区就是一个子表;
create table gpsxmg.mortion(id text,cjsj timestamp without time zone,name text)with (appendonly=true,orientation=parquet,compresstype=snappy)distributed randomly partition by range(cjsj)(partition p201701 start ('2017-01-01 00:00:00'::timestamp without time zone) inclusive,partition p201702 start ('2017-02-01 00:00:00'::timestamp without time zone) inclusive,partition p201703 start ('2017-03-01 00:00:00'::timestamp without time zone) inclusive,partition p201704 start ('2017-04-01 00:00:00'::timestamp without time zone) inclusive,partition p201705 start ('2017-05-01 00:00:00'::timestamp without time zone) inclusiveend ('2017-06-01 00:00:00'::timestamp without time zone) exclusive);
将分区p201908 在 '2019-08-15' 左右切分成两块
alter table gpsxmg.partition_table_ext split partition p2201908 at ('2019-08-16 00:00:00') into (partition p20190801, partition p20190802);
切割默认分区:
alter table gpsxmg.partition_table_ext split default partition start ('2019-08-01') end ('2019-09-01') into (partition p20190801, default partition);
如果存在default partition,则不能add分区,只能split default partition
alter table gpsxmg.partition_table_ext add partition p201908 start(DATE '2019-08-01 00:00:00') inclusive end(DATE '2019-09-01 00:00:00') exclusive;
彻底删除对应的分区表
alter table gpsxmg.partition_table_ext drop partition gpsxmg.partition_table_ext_1_prt_p201908;
清空分区表数据,相当于删除分区,然后再新建一个
alter table gpsxmg.partition_table_ext truncate partition gpsxmg.partition_table_ext_1_prt_p201908;
这几种底层都是postgresql语法,支持多级分区,这里只讲解二级分区,三级及以上在HAWQ的低版本有bug就不过多介绍了
create table table_partion_2( id int, name varchar(64), fdate varchar(10)) distributed randomly partition by range(fdate) subpartition by list(name) subpartition template( subpartition c1 values ('maoge1'), subpartition c2 values ('maoge2'))( partition p201908 start ('2019-08-01 00:00:00') end ('2019-09-01 00:00:00'))
alter table table_partion_2 alter partition p201908 drop partition c2;
alter table table_partion_2 alter partition p201908 truncate partition c2;
记得关注一波茅哥再走哦!动动你的小手指分享给你的朋友们,自己也记得收藏一波以备不时之需!