当前位置:网站首页>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)
边栏推荐
- Shell script updates stored procedure to database
- After changing the GCC version, make[1] appears in the compilation: cc: command not found
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
- How to check the lock information in gbase 8C database?
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 20
- How to improve the enthusiasm of consumers when the member points marketing system is operated?
- Initial understanding of pointer variables
- Pat 1046 shortest distance (20 points) simulation
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
- Sword finger offer 30 Stack containing min function
猜你喜欢
![[untitled] a query SQL execution process in the database](/img/de/700ee20934fc2cd4a019f761148ef9.png)
[untitled] a query SQL execution process in the database

力扣今日题-729. 我的日程安排表 I

2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition

The third level of C language punch in

Initial understanding of pointer variables

Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8](/img/16/33f5623625ba817e6e022b5cb7ff5d.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8

从顶会论文看2022年推荐系统序列建模的趋势

高数_向量代数_单位向量_向量与坐标轴的夹角

构建库函数的雏形——参照野火的手册
随机推荐
LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
Redis skip table
RobotFramework入门(一)简要介绍及使用
大厂镜像库
2.12 simulation
微服务间通信
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
3D drawing ()
Reset nodejs of the system
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
[postgraduate entrance examination English] prepare for 2023, learn list5 words
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
MySQL winter vacation self-study 2022 11 (9)
Yyds dry inventory comparison of several database storage engines
C language - Blue Bridge Cup - promised score
Which ecology is better, such as Mi family, graffiti, hilink, zhiting, etc? Analysis of five mainstream smart brands
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
Is there a case where sqlcdc monitors multiple tables and then associates them to sink to another table? All operations in MySQL
PMP每日一练 | 考试不迷路-7.5
Looking at the trend of sequence modeling of recommended systems in 2022 from the top paper