当前位置:网站首页>Fault analysis | from data_ Free exception
Fault analysis | from data_ Free exception
2022-06-22 19:43:00 【ActionTech】
author : Yang Qilong
Net name “ The north is in the south ”, Senior DBA, Mainly responsible for database architecture design and operation and maintenance platform development , Good at database performance tuning 、 Troubleshooting .
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 .
One Preface
A customer feedback query database found information_schema.tables Of data_free Value burst exception , achieve 13G about . Pictured :

It is necessary to find out what causes , This article combs the process of troubleshooting and the methods to solve problems .
Two screening
2.1 analysis
First data_free The meaning is Table space ibd After the file is written and deleted , The amount of space left without recycling .
Let the students check the primary and standby databases at the same time , Compare the file size and configuration . Find the main library of data_free The value is 13G about , The standby database is normal .

From the result, we can guess that it is related to some request actions on the main database , Void is MySQL because sql There is no result of automatic reclaiming of the space requested to be allocated for writing . Based on the information given by the front line , No other ideas , Look at the screenshot sent by the front line :

Accident from Screenshot's ibtmp1 File size found some clues , Screenshots show ibtmp1 The file size is also 13G , The standby database is the initial value .
Ignore the red arrow , see ibtmp1 File size is 13G , There seems to be some clue ,
data_freeWhether and ibtmp1 of .
2.2 Verify the conjecture
Use sysbench Create test table sbtest1 , structure 2w Bar record , Then create sbtest2 , take sbtest1 The data of Import to sbtest2 . Why do you do this , It will be explained later .
mysql > show variables like 'innodb_temp_data_file_path';
+----------------------------+-----------------------+
| Variable_name | Value |
+----------------------------+-----------------------+
| innodb_temp_data_file_path | ibtmp1:12M:autoextend |
+----------------------------+-----------------------+
1 row in set (0.00 sec)
View physics ibtmp1 file size :
[[email protected] data]# du -sm ibtmp1
12 ibtmp1
Communicate test cases , Let the system automatically generate temporary tables
mysql > create table sbtest2 like sbtest1;
Query OK, 0 rows affected (0.01 sec)
mysql > insert into sbtest2(k,c,pad) select k,c ,pad from sbtest1;
Query OK, 200000 rows affected (1.18 sec)
Records: 200000 Duplicates: 0 Warnings: 0
mysql > insert into sbtest2(k,c,pad) select k,c ,pad from sbtest1;
Query OK, 200000 rows affected (1.06 sec)
mysql > insert into sbtest2(k,c,pad) select k,c ,pad from sbtest2;
Query OK, 400000 rows affected (2.49 sec)
Records: 400000 Duplicates: 0 Warnings: 0
mysql > insert into sbtest2(k,c,pad) select k,c ,pad from sbtest2;
Query OK, 800000 rows affected (6.18 sec)
Records: 800000 Duplicates: 0 Warnings: 0
Check again ibtmp1 file size 204MB
[[email protected] data]# du -sm ibtmp1
204 ibtmp1
mysql > SELECT FILE_NAME, TABLESPACE_NAME, ENGINE, INITIAL_SIZE, TOTAL_EXTENTS*EXTENT_SIZE
-> AS TotalSizeBytes, DATA_FREE, MAXIMUM_SIZE FROM INFORMATION_SCHEMA.FILES
-> WHERE TABLESPACE_NAME = 'innodb_temporary'\G
*************************** 1. row ***************************
FILE_NAME: ./ibtmp1
TABLESPACE_NAME: innodb_temporary
ENGINE: InnoDB
INITIAL_SIZE: 12582912
TotalSizeBytes: 213909504
DATA_FREE: 207618048 ## Corresponding to the physical file size
MAXIMUM_SIZE: NULL
1 row in set (0.00 sec)
see I_S.tables Of data_free Value :

see insert select from table Temporary tables are indeed used during execution .
mysql > explain insert into sbtest2(k,c,pad) select k,c ,pad from sbtest2\G
*************************** 1. row ***************************
..
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: sbtest2
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1578168
filtered: 100.00
Extra: Using temporary ##
2 rows in set (0.00 sec)
Records: 200000 Duplicates: 0 Warnings: 0
thus , An instance of a customer can be identified because some SQL The system temporary table space is occupied during the process , After use, the temporary table space is not recycled, resulting in the initial problem . Now let's learn more about MySQL Knowledge of temporary tables .
3、 ... and Temporary table space
3.1 Introduce
ibtmp1 Is uncompressed innodb Separate tablespaces for temporary tables , adopt innodb_temp_data_file_path Parameter specifies the path to the file , File name and size , Default configuration is ibtmp1:12M:autoextend, If no location is specified , The temporary table space will be created to innodb_data_home_dir Specified path .
It should be noted that : By default , The size of this file can grow indefinitely . and 5.7 The version will not follow SQL At the end of the statement, the temporary table space is actively reclaimed , Security risks resulting in insufficient space resources .
3.2 When will temporary tables be used
When explain View the results of the execution plan extra In the column , If you include Using Temporary It means that temporary tables will be used , For example, the following common situations will usually be used :
- insert into tab1 select … from tab2 .
- group by No indexed fields or group by order by The fields are different .
- distinct The value of and group by The values are different , Cannot take advantage of sparse indexes .
Others are welcome to add .
3.3 Parameters and metadata related to temporary tables
5.7 edition :
innodb_temp_data_file_path
default_tmp_storage_engine
internal_tmp_disk_storage_engine
8.0 Versions are divided into session level and global level temporary table spaces
innodb_temp_tablespaces_dir # Specify session level creation of temporary tables to BASEDIR/data/#innodb_temp
innodb_temp_data_file_path # Global variables
internal_tmp_disk_storage_engine
Temporary tables created by users can be queried INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO
mysql > CREATE TEMPORARY TABLE t1 (c1 INT PRIMARY KEY) ENGINE=INNODB;
Query OK, 0 rows affected (0.00 sec)
mysql > SELECT * FROM INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO\G
*************************** 1. row ***************************
TABLE_ID: 54
NAME: #sqlfd5_b_0
N_COLS: 4
SPACE: 36
PER_TABLE_TABLESPACE: FALSE
IS_COMPRESSED: FALSE
1 row in set (0.00 sec)
MySQL In execution sql Tables created by the optimizer in the process , They can't get through INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO Direct view . For example, the case of this article .
3.4 How to solve ibtmp1 The problem of file space occupation
Universal restart method , Find the right time , Switch database , Restart the old main database .
By configuring
innodb_temp_data_file_pathcontrol ibtmp1 Maximum value of file , Avoid unlimited increase in table space size .innodb_temp_data_file_path= ibtmp1:12M:autoextend:max:10G12M Is the initial size of the file ,10G Is the maximum value of the file , If the maximum value is exceeded, the system will prompt an error
ERROR 1114 (HY000): The table ‘/data/msb_5_7_31/tmp#sql_xxxxx_0’ is full
Reference article
https://dev.mysql.com/doc/refman/5.7/en/innodb-temporary-tablespace.html
https://dev.mysql.com/doc/refman/8.0/en/innodb-temporary-tablespace.html
边栏推荐
猜你喜欢

小波变换db4进行四层分解及其信号重构—matlab分析及C语言实现

Xintang nuc980 usage record: basic description of development environment preparation and compilation configuration

Openpnp调试 ------ 0816飞达推0402编带
Notes on Combinatorics (V) chains in distributive lattice

K8s deploy MySQL

what? Homekit, Micah, aqara and other ecosystems can also be linked with tmall elf ecology through zhiting?

程序员工具大全【持续更新】

实验七 触发器

2年狂赚178亿元,中国游戏正在“收割”老外

84. (cesium chapter) movement of cesium model on terrain
随机推荐
取zip包中的文件名
Paopao Mart: empty souls need stories
Flutter系列-搭建Flutter开发环境
84.(cesium篇)cesium模型在地形上运动
In the first half of the year, there were 7 new unicorns in this field, and the capital scrambled to enter the market
新唐NUC980使用记录:开发环境准备与编译配置基础说明
Sre is bound to move towards the era of chaotic engineering -- Huawei cloud chaotic engineering practice
20billion vs 5billion, how much is the "dehydration" little red book worth?
NAND闪存(NAND Flash)颗粒SLC,MLC,TLC,QLC的对比
Pat a 1093 count Pat's (25 points)
org. apache. ibatis. binding. BindingException: Invalid bound statement (not found)
1.3-----Simplify 3D切片软件简单设置
Flutter series - build a flutter development environment
SSH password free login
DIV横向布局
安装Office的一些工具
Iplook 5gc successfully connected with CICA international CHF (billing function)
Mini web framework: template replacement and routing list function development | dark horse programmer
Shell script explanation (II) -- conditional test, if statement and case branch statement
数商云:数字化供应链系统搭建,赋能企业实现物流供应链的优化升级