当前位置:网站首页>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
边栏推荐
- 维智科技亮相西部数博会,时空AI技术获高度认可
- SSH password free login
- 如何用银灿IS903主控DIY自己的U盘?(练习BGA焊接的好项目)
- Human Pose Estimation浅述
- Initial experience of ABAQUS using RSG drawing plug-in
- 老师们,我想请教一个问题,我本地跑flinkcdc同步mysql数据timestamp字段解析正常,
- Programmer's tool encyclopedia [continuous update]
- 知识蒸馏之Focal and Global Knowledge Distillation for Detectors
- ABAQUS 使用RSG绘制插件初体验
- 小甲鱼老师《带你学C带你飞》的后续课程补充
猜你喜欢

推荐一个解剖学网站

Altium Designer中off grid pin解决方法
组合学笔记(五)分配格中的链

Openpnp调试 ------ 0816飞达推0402编带

China's games are "harvesting" foreigners

Active Directory用户登录报告

新唐NUC980使用记录:开发环境准备与编译配置基础说明

智能家居不知如何选?不妨看下这篇选购指南

Shell script explanation (VII) -- regular expression, sort, uniq, tr

Wavelet transform DB4 for four layer decomposition and signal reconstruction matlab analysis and C language implementation
随机推荐
集群、分布式、微服务概念和区别
Decorator mode of structural mode
shell脚本详解(二)——条件测试、if语句和case分支语句
数组对象根据id一 一对应填入(将arr1填入arr2中)
C#,入门教程——关于函数参数ref的一点知识与源程序
shell脚本详解(十)——sed编辑器的使用方法
2.什么是机械设计?
Digital business cloud: build a digital supply chain system to enable enterprises to optimize and upgrade their logistics supply chain
Shell编程规范与变量
Altium Designer中off grid pin解决方法
canvas给图片画框框
84. (cesium chapter) movement of cesium model on terrain
About Random Forest
Creator mode summary
Iplook becomes RedHat (red hat) business partner
AttributeError: ‘KeyedVectors‘ object has no attribute ‘wv‘
84.(cesium篇)cesium模型在地形上运动
数商云:解析B2B2C多用户商城系统架构设计思路,开启智能商城新时代
Shell script explanation (IV) -- while loop and until loop of loop statements (additional examples and analysis)
what? Homekit, Micah, aqara and other ecosystems can also be linked with tmall elf ecology through zhiting?