一个mysql /tmp目录爆满问题的处理
admin
2023-05-18 02:42:12
0

突然收到zabbix告警,说mysql服务器的/目录磁盘空间不足。

登录到服务器,看了下发现100GB的根目录,居然使用了差不多90GB。这台服务器上只跑了一个MySQL,应该不是日志未清理等其它原因造成的。


(说明:下面的几张截图是后期截的,当时已经有部分SQL跑完,释放掉部分磁盘空间了)

lsof |grep deleted 发现如下:

一个mysql /tmp目录爆满问题的处理可以看到这个临时文件差不多有40GB。



show processlist; 如下:

一个mysql /tmp目录爆满问题的处理

上图看的话,没有涉及到写binlog的操作,但是由于单纯的select并不会造成/tmp目录爆满的情况,所以猜测他这个同一个事务里面之前还有涉及到写binlog的操作(update、delete等)。



官方的说明:

https://dev.mysql.com/doc/refman/5.6/en/binary-log.html

When a thread that handles the transaction starts, it allocates a buffer of binlog_cache_size to buffer statements. If a statement is bigger than this, the thread opens a temporary file to store the transaction. The temporary file is deleted when the thread ends.


The Binlog_cache_use status variable shows the number of transactions that used this buffer (and possibly a temporary file) for storing statements. TheBinlog_cache_disk_use status variable shows how many of those transactions actually had to use a temporary file. These two variables can be used for tuning binlog_cache_size to a large enough value that avoids the use of temporary files.

The max_binlog_cache_size system variable (default 4GB, which is also the maximum) can be used to restrict the total size used to cache a multiple-statement transaction. If a transaction is larger than this many bytes, it fails and rolls back. The minimum value is 4096.

If you are using the binary log and row based logging, concurrent inserts are converted to normal inserts for CREATE ... SELECT or INSERT ... SELECTstatements. This is done to ensure that you can re-create an exact copy of your tables by applying the log during a backup operation. If you are using statement-based logging, the original statement is written to the log.


当事务开始时,它将缓冲区语句分配一个binlog_cache_size大小的缓冲区(我这里设置的是16777216bytes,即16MB)。 如果一个语句大于此,线程将打开一个临时文件来存储事务(默认是存放在/tmp/目录下)。 当线程结束时,临时文件会自动被删除。


上面就是因为事务里面的临时文件超过16MB了,被放到/tmp目录下了,但是这个临时文件实在太大了,导致磁盘空间不足告警了。


解决方法:

等上面的查询结束后,我们先关闭mysqld。(条件能允许的话,当然是让查询自己结束。如果直接kill掉的话,估计回滚也要话挺长时间的)


然后调整mysql的tmpdir到其他更大的磁盘去。

mkdir /bdata/mysql_tmp

chown mysql.mysql /bdata/mysql_tmp -R

chown 1777 -R /bdata/mysql_tmp -R

vim /etc/my.cnf 

[mysqld]

tmpdir = /bdata/mysql_tmp


然后启动mysql即可

再次执行lsof|grep deleted 可以看到临时文件的路径已经改到了/bdata/mysql_tmp目录下了。

一个mysql /tmp目录爆满问题的处理


相关内容

热门资讯

联合国秘书长欢迎黎以延长停火 新华社联合国5月16日电(记者尚绪谦)联合国秘书长发言人办公室16日说,秘书长古特雷斯欢迎黎巴嫩与以...
如何让“彩礼”回归于“礼”?一... 黄河水浇灌出的宁夏红寺堡是中国最大的生态移民安置区,宁南八县的乡音在此交汇,对美好生活的期盼与发展中...
原创 外... 外星翻译官的翻车现场:地球语言真的太难了! 银河系翻译官协会(假想机构)最近发布了一份年度报告,总...
首飞成功!已突破大重量载荷发射... 科技日报记者 付毅飞 实习生 张城辉 记者从蓝箭航天获悉,5月14日11时0分,朱雀二号改进型遥五运...
京东携手MAXHUB共推AI智... PChome消息,近日,京东与智能会议平板领域领军品牌MAXHUB正式签署战略合作协议,标志着双方战...
29个智能气象站启动业务试运行 本报北京5月15日电(记者李红梅)记者从中国气象局获悉:北京密云等29个智能气象站已于近日启动业务试...
广西一载15人车辆坠河,10人... 记者从广西环江毛南族自治县相关方面获悉,据初步了解,5月16日21时30分许,一辆汽车在环江县洛阳镇...
iOS 26.5更新苹果地图两... 苹果地图是iOS 26.5此次更新中获得新功能的应用之一。以下是地图用户需要了解的最新变化。 推荐...
每经热评 | 黄仁勋喝蜜雪冰城... 每经评论员 朱成祥 黄仁勋近期到访北京,被拍到在胡同喝豆汁、吃炸酱面、举着蜜雪冰城饮料。他表情轻松,...
我省3项目被列入工信部先进计算... 本报太原5月15日讯(记者王蕾)近日,工业和信息化部公布了2025年先进计算赋能新质生产力典型应用案...