https://zhuanlan.zhihu.com/p/110927990
https://www.modb.pro/db/87388
postgresql 分区表
传统的分区表创建比较繁琐,涉及到触发器,继承,触发器函数等,维护相对困难,postgresql10之后支持内置的分区表。
1创建父表
create table test (id int4,times timestamp(0),name text)
partition by range(times)(目前只支持range以及list)
根据times字段的范围进行分区
2 创建子表
create table test_sun partition of test for values from ('2017-8-19') to ('2017-9-19')
# 修改replica identity 配置
alter table test_sun replica identity full
其中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')
5删除分区
a:drop table(最好不用)
b:alter table 父表名 detach partition of 分区表名
6恢复解绑的分区
alter table 父表名 attach partition 子表名 for values from () to ()
以上完成分区表,是不是比继承简单很多,新建一个新的分区表后只需创建索引,而无需像传统的分区表那样修改触发函数
最后
以上就是美满猫咪最近收集整理的关于postgresql 分区表,分表的全部内容,更多相关postgresql内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复