当前位置:网站首页>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
边栏推荐
- .Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
- PHP调用纯真IP数据库返回具体地址
- MPLS experiment
- Find ID value MySQL in string
- 免费手机号码归属地API查询接口
- 2022 polymerization process test question simulation test question bank and online simulation test
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
- Day-16 set
- About IPSec
- 爱可可AI前沿推介(7.7)
猜你喜欢
图像像素读写操作
Leetcode brush questions: binary tree 19 (merge binary tree)
visual stdio 2017关于opencv4.1的环境配置
[pytorch practice] write poetry with RNN
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
Cookie
leetcode刷题:二叉树24(二叉树的最近公共祖先)
如何将 @Transactional 事务注解运用到炉火纯青?
2022广东省安全员A证第三批(主要负责人)考试练习题及模拟考试
Day-18 hash table, generic
随机推荐
test
免费手机号码归属地API查询接口
2022 polymerization process test question simulation test question bank and online simulation test
Object. Simple implementation of assign()
【从 0 开始学微服务】【01】什么是微服务
初学XML
[statistical learning method] learning notes - logistic regression and maximum entropy model
如何将 @Transactional 事务注解运用到炉火纯青?
Day-17 connection set
leetcode刷题:二叉树22(二叉搜索树的最小绝对差)
How does MySQL create, delete, and view indexes?
[pytorch practice] use pytorch to realize image style migration based on neural network
MPLS experiment
Day-18 hash table, generic
PHP调用纯真IP数据库返回具体地址
IPv6 experiment
数据库安全的重要性
[difficult and miscellaneous]pip running suddenly appears modulenotfounderror: no module named 'pip‘
Aosikang biological sprint scientific innovation board of Hillhouse Investment: annual revenue of 450million yuan, lost cooperation with kangxinuo
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式