du -h /* |sort -nr 使用此命令一步步排查发现/var/lib/mysql/zabbix/这个目录占用磁盘空间较大
发现history_log.ibd这个文件最大,达到了38G,此文件对应的是zabbix库里的history_log表
找到问题原因后就好解决,进入zabbix,删除history_log表较早的数据即可
进入MySQL的zabbix库
delete from history_log where clock < 1540483200; 删除小于这个时间戳的数据
optimize table history_log delete操作以后使用optimize table table_name 会立刻释放磁盘空间
df -h 最后再验证一下磁盘空间是否有变化
先删除 history_log.
delete from history_log where clock < 1540483200; 删除小于这个时间戳的数据
optimize table history_log
依然空间占用很大。使用以下命令查询tab占用:
MariaDB [zabbix]> SELECT table_name AS
“Tables”, round(((data_length + index_length) / 1024 / 1024), 2) “Size
in MB” FROM information_schema.TABLES WHERE table_schema = ‘zabbix’
ORDER BY (data_length + index_length) DESC;
————————————–+
| Tables | Size in MB |
————————————–+
| history_text | 776627.66 |
| history_uint | 7623.14 |
| history | 1819.95 |
| trends_uint | 541.81 |
| history_str | 404.22 |
| trends | 246.09 |
| events | 190.95 |
| alerts | 139.75 |
| auditlog | 36.09 |
| sessions | 30.14 |
| event_recovery | 16.55 |
| history_log | 16.39 |
| items | 7.11 |
| items_applications | 2.80 |
可以看到,history_text占据了绝对空间。
使用以下命令删除7天前的history_text:
delete from history_text where clock <1586361600;
执行时间较长。等待中
参考来源:https://www.cnblogs.com/leon2659/p/9924627.html
