linux下mysql tmp满_MySQL服务器/tmp目录被占满
案例分享-MySQL服務器/tmp目錄被占滿
描述:
MySQL服務器在每天的22點/tmp目錄磁盤空間被占滿,持續10分鐘左右,然后自動恢復./tmp目錄大小10G,平時可用空間8G左右.MySQL版本 5.5
分析
1. ? ? ? 在問題出現時,進入/tmp目錄,ls –al查看具體文件.
2. ? ? ? 在問題出現時,登錄MySQL,執行show processlist查看是否存在異常SQL.
3. ? ? ? 查看MySQL慢查詢日志.
4. ? ? ? MySQL配置情況:
a) ? ? ? ? default_storage_engine ? ? ? ? = InnoDB
b) ? ? ? ? transaction_isolation ? ? ? ? ? = READ-COMMITTED
c) ? ? ? ? binlog_format ? ? ? ? ? ? ? ? = mixed
d) ? ? ? ? binlog_cache_size ? ? ? ? ? ? ?= 32K
e) ? ? ? ? max_binlog_cache_size ? ? ? ? = 18446744073709547520
f) ? ? ? ? ?tmpdir ? ? ? ? ? ? ? ? ? ? ? = /tmp
總結
1. ? ? ? InnoDB存儲引擎,在READ-COMMITTED事務隔離級別的情況下(默認的級別是REPEATABLE-READ),普通的DELETE操作,在記錄binlog的時候,會采用ROW模式.(暫時還不清楚原因,以后分析).
2. ? ? ? 程序在每天的22點,有一個清理的定時任務.自動刪除R表的數據,如下:
delete from R where time < xxx;
將某天之前的數據清除.但是該表比較大,近50G.
3. ? ? ? MySQL參數
binlog_cache_size
max_binlog_cache_size
參考http://dev.mysql.com/doc/refman/5.5/en/replication-options-binary-log.html
4. ? ? ? 每次執行定時任務的時候,因為binlog記錄的是ROW模式,再加上表的數據量比較大,binlog緩存一定會超過32K,結果就會在/tmp目錄下生成臨時文件(參考: 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),MySQL默認配置,在64位系統情況下,binlog文件大小最大可以達到16EB.但是系統的/tmp目錄是10G,所以事務執行一半,磁盤空間被占滿,事務回滾.
5. ? ? ? 事后查看R表的數據以及binlog記錄,驗證了第4步的推論.
解決
在沒有新數據寫入的前提下,把確定保留的數據先放到新表里面,然后刪除舊表,再把新表重命名.
create table R_20130220 select * FROM R where ?time >= xxx;
DROP TABLE R;
RENAME TABLE R_20130220 TO R;
隔天觀察nagios和cacti監控,故障恢復.
原文:http://2853725.blog.51cto.com/2843725/1394423
總結
以上是生活随笔為你收集整理的linux下mysql tmp满_MySQL服务器/tmp目录被占满的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java mvc 断点续传_用Sprin
- 下一篇: mysql 提高电脑配置_Mysql配