当前位置:网站首页>Conversion from non partitioned table to partitioned table and precautions
Conversion from non partitioned table to partitioned table and precautions
2022-07-07 12:56:00 【PHP Development Engineer 】
Sometimes data archiving is not considered when designing at the beginning . Data archiving is not a simple export delete. Because our databases are generally delete Don't free up space . But we usually encounter insufficient space in the database , We have to face this problem . Of course, you can also do space recycling for defragmentation . I don't like it very much , Especially when it's a big watch .MySQL Once you surpass 100G Of , I dare not do it in online environment .Oracle I have done online recycling of 20T Table of , debris 800G, Recycled once and made it 55 Hours ( No downtime )
Personally, I think the best way is to use zoning , It's easy to say whether to migrate partitions or archive partitions . Generally, the partition is truncated , Soon . But what if a table has not been partitioned before ?
Let's give an example
create table b (id int ,a varchar2(10),time date); Common heap table simulation 5 Data
insert into b values (1,'a',sysdate-120);
insert into b values (2,'b',sysdate-90);
insert into b values (3,'c',sysdate-60);
insert into b values (4,'d',sysdate-30);
insert into b values (5,'e',sysdate);Generally speaking, we have to use time . So time indexing .
create index b1 on b (time);Generally, tables have primary keys , stay Oracle The business document number should be used as the primary key , stay MySQL of use ID Self increment has no business meaning . stay PG According to the in Oracle Just come .
Alter table b add constraint pkb primary key(id);by B Add primary key to the table , Note here that it must be named by itself rather than ordered by the database itself . Because there is no problem with normal masters and slaves , But there are OGG In this case, it is a pit . Later I'll talk about why .
ALTER TABLE b MODIFY
PARTITION BY RANGE (time)
(
PARTITION b1 VALUES LESS THAN (TO_DATE ('2022-03-01', 'YYYY-MM-DD')),
PARTITION b2 VALUES LESS THAN (TO_DATE ('2022-04-01', 'YYYY-MM-DD')),
PARTITION b3 VALUES LESS THAN (TO_DATE ('2022-05-01', 'YYYY-MM-DD')),
PARTITION b4 VALUES LESS THAN (TO_DATE ('2022-06-01', 'YYYY-MM-DD')),
PARTITION b5 VALUES LESS THAN (TO_DATE ('2022-07-01', 'YYYY-MM-DD'))
) online
UPDATE INDEXES
(
pkb GLOBAL,
b1 LOCAL
);This is the command to convert non partitioned tables into separate tables online . Notice that in the red part, I specify the primary key name , If it is automatic, it is the name of automatic . The pit mentioned above is right here , Because in OGG scenario , The automatic name of the target side, that is, the downstream database, is different from that of the upstream side of the source side . Executing this command will cause OGG The interrupt .
Is this a database problem or OGG The problem of ? I don't think it's , It's about getting familiar with the product . After execution, you can see that the table has become partitioned .
At this time, the expired data will be truncated as long as drop partition That's all right. , Of course, pay attention to one UPDATE GLOBAL INDEXES; Otherwise, the data cannot be written .
The source code attachment has been packaged and uploaded to Baidu cloud , You can download it yourself ~
link : https://pan.baidu.com/s/14G-bpVthImHD4eosZUNSFA?pwd=yu27 Extraction code : yu27 Baidu cloud link is unstable , It may fail at any time , Let's keep it tight .
If Baidu cloud link fails , Please leave me a message , When I see it, I will update it in time ~
Open source address Code cloud address : http://github.crmeb.net/u/defu
Github Address : http://github.crmeb.net/u/defu
边栏推荐
猜你喜欢
![[statistical learning method] learning notes - support vector machine (Part 2)](/img/bc/bb4f809ff434fabc10f8e97f592fa7.png)
[statistical learning method] learning notes - support vector machine (Part 2)

Master formula. (used to calculate the time complexity of recursion.)

How to apply @transactional transaction annotation to perfection?

The left-hand side of an assignment expression may not be an optional property access. ts(2779)

智云健康上市:市值150亿港元 SIG经纬与京新基金是股东

ISPRS2021/遥感影像云检测:一种地理信息驱动的方法和一种新的大规模遥感云/雪检测数据集

.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst

leetcode刷题:二叉树19(合并二叉树)

Image pixel read / write operation

2022聚合工艺考试题模拟考试题库及在线模拟考试
随机推荐
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
处理链中断后如何继续/子链出错removed from scheduling
聊聊Redis缓存4种集群方案、及优缺点对比
[statistical learning method] learning notes - support vector machine (I)
非分区表转换成分区表以及注意事项
Simple implementation of call, bind and apply
Preorder, inorder and postorder traversal of binary tree
【二叉树】删点成林
Leetcode question brushing: binary tree 26 (insertion operation in binary search tree)
2022-07-07 Daily: Ian Goodfellow, the inventor of Gan, officially joined deepmind
Leetcode skimming: binary tree 21 (verifying binary search tree)
mysql怎么创建,删除,查看索引?
ip2long之后有什么好处?
Ip2long and long2ip analysis
达晨与小米投的凌云光上市:市值153亿 为机器植入眼睛和大脑
Connect to blog method, overload, recursion
ip2long与long2IP 分析
关于 appium 启动 app 后闪退的问题 - (已解决)
【从 0 开始学微服务】【03】初探微服务架构
MPLS experiment