当前位置:网站首页>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)
边栏推荐
- 2345 file shredding, powerful file deletion tool, unbound pure extract version
- Introduction to robotframework (I) brief introduction and use
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
- What should we pay attention to when using the built-in tool to check the health status in gbase 8C database?
- Qt发布exe软件及修改exe应用程序图标
- C语言sizeof和strlen的区别
- 全国大学生信息安全赛创新实践赛初赛---misc(永恒的夜)
- 一个复制也能玩出花来
- Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
- The third level of C language punch in
猜你喜欢
![[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation](/img/e4/890e84ab8326e029c4915163904d85.jpg)
[Digital IC manual tearing code] Verilog asynchronous reset synchronous release | topic | principle | design | simulation

C language - Blue Bridge Cup - promised score

Black high-end responsive website dream weaving template (adaptive mobile terminal)
![[matlab] access of variables and files](/img/cf/6f3cfdc4310fcf0bdcaa776d68261e.jpg)
[matlab] access of variables and files
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17](/img/85/2635afeb2edeb0f308045edd1f3431.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17

2345 file shredding, powerful file deletion tool, unbound pure extract version

3D drawing ()
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12](/img/b1/926d9b3d7ce9c5104f3e81974eef07.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 12

Deeply analyze the chain 2+1 mode, and subvert the traditional thinking of selling goods?

Universal crud interface
随机推荐
Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures
Pure QT version of Chinese chess: realize two-man, man-machine and network games
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
Introduction to robotframework (II) app startup of appui automation
微服务注册与发现
Trends in DDoS Attacks
2020.02.11
PAT甲级 1033 To Fill or Not to Fill
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
CSP numeric sort
MySQL (IV) - transactions
Yyds dry inventory comparison of several database storage engines
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
How to accurately identify master data?
Building the prototype of library functions -- refer to the manual of wildfire
Shell script updates stored procedure to database
Day 50 - install vsftpd on ceontos6.8
Maturity of master data management (MDM)
07 singleton mode
一个复制也能玩出花来