标题
postgresql 分区表
传统的分区表创建比较繁琐,涉及到触发器,继承,触发器函数等,维护相对困难,postgresql10之后支持内置的分区表。
1创建父表
create table test (id int4,times timestamp(0),name text)
partition by range(times)
根据times字段的范围进行分区
2 创建子表
create table test_sun partition of test for values from (‘2017-8-19’) to (‘2017-9-19’)
其中partition of后接表名为父表名称
3 创建索引
create index index1 on test_sun using btree(times)
4插入数据测试
insert into test (id,times,name) values(1,‘2017-8-19’,‘1’),(1,‘2017-8-21’,‘1’),(1,‘2017-8-22’,‘1’),(1,‘2017-8-23’,‘1’)