当前位置:网站首页>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)
边栏推荐
- 【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
- Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
- Solution: attributeerror: 'STR' object has no attribute 'decode‘
- 剑指 Offer 30. 包含min函数的栈
- Redis skip table
- Sword finger offer 29 Print matrix clockwise
- CobaltStrike-4.4-K8修改版安装使用教程
- RobotFramework入门(二)appUI自动化之app启动
- Pure QT version of Chinese chess: realize two-man, man-machine and network games
猜你喜欢
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation
Httprunnermanager installation (III) - configuring myql Database & initialization data under Linux
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Pure QT version of Chinese chess: realize two-man, man-machine and network games
A doctor's 22 years in Huawei
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
一位博士在华为的22年
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
【MySQL 15】Could not increase number of max_ open_ files to more than 10000 (request: 65535)
[matlab] access of variables and files
随机推荐
Thinking on Architecture Design (under continuous updating)
米家、涂鸦、Hilink、智汀等生态哪家强?5大主流智能品牌分析
Introduction to robotframework (II) app startup of appui automation
Template_ Quick sort_ Double pointer
Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?
Looking at the trend of sequence modeling of recommended systems in 2022 from the top paper
Force buckle 146 LRU cache
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures
Apt installation ZABBIX
PMP practice once a day | don't get lost in the exam -7.5
全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
Maturity of master data management (MDM)
Sword finger offer 30 Stack containing min function
3D drawing ()
事故指标统计
Pat 1046 shortest distance (20 points) simulation
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
Is there a case where sqlcdc monitors multiple tables and then associates them to sink to another table? All operations in MySQL
Pat grade a 1033 to fill or not to fill