当前位置:网站首页>Technology sharing | what if Undo is too big
Technology sharing | what if Undo is too big
2022-07-06 02:41:00 【ActionTech】
author : Wang Yuchen
Aikesheng Database Engineer , be responsible for MySQL Routine maintenance and DMP Product support .
In this paper, the source : Original contribution
* Produced by aikesheng open source community , Original content is not allowed to be used without authorization , For reprint, please contact the editor and indicate the source .
The problem background
There are users using MySQL5.7 The database of , encounter undo Soaring situation , After investigation, there is a slow SQL It has been executed for tens of thousands of seconds, but it is still not over , Resulting in subsequent transactions undo Can't clean up , More and more
On-line truncate undo log Enabled , Will slow down SQL kill After falling ,undo Larger than innodb_max_undo_log_size Set size , but undo The file did not shrink immediately
Test verification
The test parameters are as follows , Turn on innodb_undo_log_truncate
mysql> show variables like '%undo%';
+--------------------------+-----------+
| Variable_name | Value |
+--------------------------+-----------+
| innodb_max_undo_log_size | 104857600 |
| innodb_undo_directory | ./ |
| innodb_undo_log_truncate | ON |
| innodb_undo_logs | 128 |
| innodb_undo_tablespaces | 3 |
+--------------------------+-----------+
5 rows in set (0.00 sec)
simulation undo growth , exceed innodb_max_undo_log_size Set size
# du -sh ./undo*
152M ./undo001
296M ./undo002
15M ./undo003
Check out the official documents undo Clean up strategy , It can be summarized as follows :
1、 Enable innodb_undo_log_truncate after , exceed innodb_max_undo_log_size Set the size of undo Table spaces are marked as truncated
2、 Marked undo The rollback segment of the table space is set to inactive , Cannot assign to a new transaction
3、purge Threads release unnecessary rollback segments
4、 After releasing the rollback segment ,undo The table space is truncated to its initial size 10M
You can see it shrinking undo Before size , need purge The thread releases the rollback segment first , Here is another parameter innodb_purge_rseg_truncate_frequency, The default value is 128, Express purge Every time a thread calls 128 Time , Release the rollback segment once
In the background of this problem , This parameter sets the default value
mysql> show variables like 'innodb_purge_rseg_truncate_frequency';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| innodb_purge_rseg_truncate_frequency | 128 |
+--------------------------------------+-------+
1 row in set (0.01 sec)
So in order to shrink as soon as possible undo file , We can innodb_purge_rseg_truncate_frequency Turn it down , Improve purge How often does the thread release rollback segments
// Turn down the value
mysql> show variables like 'innodb_purge_rseg_truncate_frequency';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| innodb_purge_rseg_truncate_frequency | 16 |
+--------------------------------------+-------+
1 row in set (0.01 sec)
// achieve purge Number of thread calls , Release the rollback segment ,undo The table space is truncated
# du -sh ./undo*
10M ./undo001
10M ./undo002
15M ./undo003
MySQL8.0 newly added Manual Truncation
MySQL8.0 New support for SQL Statement to manage undo Table space
1、 Need at least three active undo Table space , Because there are two active undo Table space to support Automated Truncation
Create a... By hand undo Table space , Must be .ibu ending
mysql> create undo tablespace undo_003 add datafile '/data/mysql/data/3307/undo_003.ibu';
Query OK, 0 rows affected (0.27 sec)
// Three are in active State of undo Table space
mysql> SELECT NAME, STATE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME LIKE '%undo%';
+-----------------+--------+
| NAME | STATE |
+-----------------+--------+
| innodb_undo_001 | active |
| innodb_undo_002 | active |
| undo_003 | active |
+-----------------+--------+
3 rows in set (0.00 sec)
2、 Manually cut undo Table space , You need to undo The tablespace is set to inactive
// simulation undo growth
# du -sh ./undo*
81M ./undo_001
157M ./undo_002
26M ./undo_003.ibu
mysql> ALTER UNDO TABLESPACE innodb_undo_002 SET INACTIVE;
Query OK, 0 rows affected (0.01 sec)
3、 Manual settings inactive after ,undo Table spaces are marked as truncated ,purge Threads will increase the return frequency , Quickly empty and finally cut undo Table space , The status changes to empty
mysql> SELECT NAME, STATE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME LIKE '%undo%';
+-----------------+--------+
| NAME | STATE |
+-----------------+--------+
| innodb_undo_001 | active |
| innodb_undo_002 | empty |
| undo_003 | active |
+-----------------+--------+
//undo File shrink
# du -sh ./undo*
81M ./undo_001
2.1M ./undo_002
26M ./undo_003.ibu
4、empty State of undo Tablespaces can be reactivated
mysql> ALTER UNDO TABLESPACE innodb_undo_002 SET ACTIVE;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT NAME, STATE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME LIKE '%undo%';
+-----------------+--------+
| NAME | STATE |
+-----------------+--------+
| innodb_undo_001 | active |
| innodb_undo_002 | active |
| undo_003 | active |
+-----------------+--------+
3 rows in set (0.01 sec)
5、MySQL8.0 Support deleting tablespaces , But the premise is that the table space is empty state
mysql> ALTER UNDO TABLESPACE undo_003 SET INACTIVE;
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT NAME, STATE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME LIKE '%undo%';
+-----------------+--------+
| NAME | STATE |
+-----------------+--------+
| innodb_undo_001 | active |
| innodb_undo_002 | active |
| undo_003 | empty |
+-----------------+--------+
3 rows in set (0.01 sec)
mysql> DROP UNDO TABLESPACE undo_003;
Query OK, 0 rows affected (0.02 sec)
mysql> SELECT TABLESPACE_NAME, FILE_NAME FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE LIKE 'UNDO LOG';
+-----------------+------------+
| TABLESPACE_NAME | FILE_NAME |
+-----------------+------------+
| innodb_undo_001 | ./undo_001 |
| innodb_undo_002 | ./undo_002 |
+-----------------+------------+
2 rows in set (0.01 sec)
边栏推荐
- 高数_向量代数_单位向量_向量与坐标轴的夹角
- "Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
- RobotFramework入门(三)WebUI自动化之百度搜索
- I changed the driver to 5.1.35, but it is still the same error. I can succeed even now, but I will report this every time I do an SQL operation
- Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
- LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
- A doctor's 22 years in Huawei
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
- Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
猜你喜欢
A doctor's 22 years in Huawei
Apt installation ZABBIX
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Initial understanding of pointer variables
高数_向量代数_单位向量_向量与坐标轴的夹角
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
RobotFramework入门(二)appUI自动化之app启动
Blue Bridge Cup group B provincial preliminaries first question 2013 (Gauss Diary)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
随机推荐
Reset nodejs of the system
There are so many giants, why should we independently develop POS store cashier system?
07 singleton mode
Introduction to robotframework (I) brief introduction and use
SSM assembly
继承的构造函数
解决:AttributeError: ‘str‘ object has no attribute ‘decode‘
力扣今日题-729. 我的日程安排表 I
MySQL winter vacation self-study 2022 11 (8)
Maturity of master data management (MDM)
Day 50 - install vsftpd on ceontos6.8
2.11 simulation summary
Accident index statistics
有沒有sqlcdc監控多張錶 再關聯後 sink到另外一張錶的案例啊?全部在 mysql中操作
Six stone management: why should leaders ignore product quality
Atcoder beginer contest 233 (a~d) solution
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
Number conclusion LC skimming review - 1
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15