当前位置:网站首页>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
边栏推荐
- 新唐NUC980使用记录:开发环境准备与编译配置基础说明
- Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)
- ActiveReports报表实战应用教程(十九)——多数据源绑定
- 1.4-----PCB设计?(电路设计)确定方案
- Service实战:使用Service完成一个下载任务
- How to choose smart home? Take a look at this shopping guide
- NLP-D57-nlp比赛D26&刷题D13&读论文&&找了一个多小时bug
- vs2008 水晶报表升级到 vs2013对应版本
- 20billion vs 5billion, how much is the "dehydration" little red book worth?
- 组合学笔记(五)分配格中的链
猜你喜欢
Notes on Combinatorics (V) chains in distributive lattice
组合学笔记(五)分配格中的链

5g short message solution

ActiveReports报表实战应用教程(十九)——多数据源绑定

k8s部署mysql

Pull down refresh and pull up to load more listviews

Iplook becomes RedHat (red hat) business partner

K8s deploy MySQL

Shell编程规范与变量

1.2-----机械设计工具(CAD软件)和硬件设计工具(EDA软件)及对比
随机推荐
shell脚本详解(七)——正则表达式、sort、uniq、tr
《被讨厌的勇气》读后感
Active directory user logon Report
实验七 触发器
Iplook 5gc successfully connected with CICA international CHF (billing function)
Service实战:使用Service完成一个下载任务
Teachers, I want to ask you a question. I run flinkcdc locally to synchronize MySQL data. The timestamp field parsing is normal,
Input two strings and output the longest substring with the same length
Experiment 7 trigger
Intelligent procurement system solution for processing and manufacturing industry: help enterprises realize integrated and Collaborative Procurement in the whole process
数组对象实现一 一对比(索引和id相同的保留原数据,原数组没有的数据从默认列表加进去)
修改antd tree组件,使其子类横向排列。
Shell script (V) -- function
下拉刷新及上拉加载更多的ListView
安装Office的一些工具
推荐一个解剖学网站
Online generation of placeholder pictures
通过base64下载文件(将base64转为blob)
【干货|接口测试必备技能-常见接口协议解析】
结构型模式之装饰者模式