当前位置:网站首页> 一次mysql的.ibd文件过大处理过程记录
一次mysql的.ibd文件过大处理过程记录
2022-06-29 13:25:00 【1024问】
一条zabbix微信的磁盘告警打破了往常的宁静
收到告警之后发现是mysql的datadir目录,按着平时习惯开始排查;过程就不说了,最后发现某个库的目录大小异常,然后进去查看之后发现jdp_tb_trade.ibd过大,达到46G;跟真实数据量不符,就此打算对它下手处理。
那么,我们知道ibd文件是每个数据库里面每个表的数据空间,每个表的数据和索引都会存在自已的表空间中。
这么重要的东西肯定不能直接在线上操作,毕竟之前完全不知道处理这个东西会产生什么影响,那接下来就是测试环境的再现过程了:
测试环境:配置直接cp线上的my.cnf
然后建库建表,插入数据,使该表的ibd文件增大
最后如图:

该文件46G,表里面的数据也有八百多万条,接下来就是再现线上环境的操作了(线上环境增删操作多),先删个10数据,并且用优化命令对该表进行优化(optimize):

但是发现在等待该命令执行结果的过程中,根目录一直在增长:

直到跟目录被占用百分百之后,优化命令报错了:

报错之后跟目录空间瞬间释放了:

这里我当时猜想到是因为临时表的问题,但是不知道怎么改临时表的存储目录,那肯定是不懂就问。
问了DBA 大佬后,说是修改tmpdir参数即可(默认是指向tmp目录):
熟练的vim my.cnf
在[mysqld]下添加:
tmpdir = /ssd_data2/158mysql/107.sla
重启mysql实例
在mysql命令符下查看该参数目录是否生效:

那就再执行一遍优化命令:


成功了,文件也缩小了一个G。
接下来我又进一步测试,删除表里面数据,只保留10万条数据;再执行optimize命令,并且观察目录占用大小情况:



这里值得一提的是:optimize命令执行时间只用了15分钟,通过观察目录的变化发现临时表大小大概在45G左右。
接下来是总结:
1)我原以为做一些小小的改动(只删除了10条数据)会很快得到实验的结果,结果可以在图上面看到optimize命令执行了一个半小时;但是后面我再一次测试发现只用了15分钟,可能是服务器上其他业务影响了,时间上不好下结论。
这个命令会产生锁表的效应,所以时间上需要注意。
2)学习知识点:
1、ibd文件为何物,里面是放什么东西的:
上面也说到,是放表的元数据,索引。
2、optimize这个命令的相关知识,会对数据库造成什么影响等:
已知有:
执行过程中会锁表
会产生临时表,占用一定的空间
会影响主从延迟
(欢迎留言补充)
3、tmpdir这个参数:
临时表指定存放目录
可以跟innodb_tmpdir参数对比学习
4、这里要提一个参数 “innodb_file_per_table=1”
配置文件里最好把这个参数打开,因为生产环境用的是innoDB的引擎,然后innodb会默认将所有库的表数据都存储在一个共享空间中:ibdata1,这样不方便我们平时的优化。
该参数是让每个表都会产生一个独立的ibd文件(也就是数据空间)
3)为什么会产生这样的事情呢?:
个人理解:平时我们删除数据时,会使得表的ibd文件产生空隙:也就是说,删除数据之后它会傻傻的空在哪里,如果没有数据补进来就会一直空着;然后重复这增加,删除一系列操作之后,该文件随着时间的推移变得越来越大。
目前我所知没有特别好的办法避免这一点,不过定时优化就好;
总结
到此这篇关于一次mysql的.ibd文件过大处理过程的文章就介绍到这了,更多相关mysql .ibd文件过大处理内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- 从Mpx资源构建优化看splitChunks代码分割
- Detailed explanation of machine learning out of fold prediction | using out of fold prediction oof to evaluate the generalization performance of models and build integrated models
- Intuition and Implementation: batch normalization
- Wechat applet: Halloween avatar box generation tool
- tcpdump如何对特定的tcp标志位进行过滤
- How to install MySQL 8.0 on rocky Linux and almalinux
- Equivalence class partition method for test case design method
- urllib urllib2
- Installation and removal of cover for CPU protection on desktop motherboard
- Summary of binary tree exercises
猜你喜欢

go-zero微服务实战系列(七、请求量这么高该如何优化)

Lecun published a research plan for the next decade: AI autonomous intelligence with a 62 page paper

Korean AI team plagiarizes the shock academic world! One tutor with 51 students, or plagiarism recidivist

Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching

Equivalence class partition method for test case design method

ANSVC无功补偿装置在河北某购物广场中的应用

直觉与实现:Batch Normalization

Application of ansvc reactive power compensation device in a shopping mall in Hebei

靠代理,靠买断,国产端游的蛮荒时代等待下一个《永劫无间》

微信小程序:装B神器P图修改微信流量主小程序源码下载趣味恶搞图制作免服务器域名
随机推荐
投资人跌下神坛:半年0出手,转行送外卖
win10安装Monggodb的基本使用教程
人不成熟的特征
Detailed explanation of machine learning out of fold prediction | using out of fold prediction oof to evaluate the generalization performance of models and build integrated models
Stable currency risk profile: are usdt and usdc safe?
Deecamp2022 officially opened! Likaifu and zhangyaqin personally teach master courses 𞓜 innovation
直觉与实现:Batch Normalization
I talked about exception handling for more than half an hour during the interview yesterday
揭秘百度智能测试在测试自动执行领域实践
Cicd introduction [easy to understand]
Lecun published a research plan for the next decade: AI autonomous intelligence with a 62 page paper
win11怎么看cpu几核几线程? win11查看cpu是几核几线程的教程
微信小程序:修复采集接口版云开发表情包
28000 word summary of callable and future interview knowledge points. After reading it, I went directly to ByteDance. Forgive me for being a little floating (Part 2)
STM32 watchdog study
测试用例设计方法之等价类划分方法
Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here
Detailed explanation of PDB symbol library files
微信小程序:图片秒加水印制作生成
[graduation season] it's worth it all the way over the past four years -- advice from the senior students