当前位置:网站首页>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)
边栏推荐
- 有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
- ReferenceError: primordials is not defined错误解决
- JS events (add, delete) and delegates
- Accident index statistics
- HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
- Structural theme model (I) STM package workflow
- [Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation
- Maturity of master data management (MDM)
- "Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.3 linear algebra_ Learning thinking and exercise answers
猜你喜欢

Yyds dry inventory comparison of several database storage engines

剑指 Offer 30. 包含min函数的栈
![[Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology](/img/47/e895a75eb3af2aaeafc6ae76caafe4.jpg)
[Yu Yue education] basic reference materials of digital electronic technology of Xi'an University of Technology

Referenceerror: primordials is not defined error resolution

Universal crud interface

Network Security Learning - Web vulnerabilities (Part 1)
![[untitled] a query SQL execution process in the database](/img/de/700ee20934fc2cd4a019f761148ef9.png)
[untitled] a query SQL execution process in the database

Sword finger offer 29 Print matrix clockwise

Initial understanding of pointer variables

"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
随机推荐
Structural theme model (I) STM package workflow
Number conclusion LC skimming review - 1
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
Maturity of master data management (MDM)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
Briefly describe the implementation principle of redis cluster
Y a - t - il des cas où sqlcdc surveille plusieurs tables et les associe à une autre? Tout fonctionne dans MySQL
Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
DDoS attacks - are we really at war?
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
Accident index statistics
How to accurately identify master data?
Bigder:34/100 面试感觉挺好的,没有收到录取
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
Redis cluster deployment based on redis5
Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO
Large scale DDoS attacks take Myanmar offline
QT release exe software and modify exe application icon