注:也可以修改配置文件改善,但是效果不大,彻底解决办法就是做数据表分区
Zabbix的history相关数据表数据太大,执行表分区操作过程
一、查询zabbix数据库大小
mysql> select table_schema, concat(truncate(sum(data_length)/1024/1024,2),' mb') as data_size,concat(truncate(sum(index_length)/1024/1024,2),'mb') as index_size from information_schema.tables group by table_schema order by data_size desc;
+--------------------+------------+------------+
| table_schema | data_size | index_size |
+--------------------+------------+------------+
| zabbix | 8326.06 mb | 3031.85mb |
| jumpserver | 26.57 mb | 8.21mb |
| mysql | 2.49 mb | 0.21mb |
| information_schema | 0.15 mb | 0.00mb |
| sys | 0.01 mb | 0.00mb |
| performance_schema | 0.00 mb | 0.00mb |
+--------------------+------------+------------+
6 rows in set (0.40 sec)
**发现Zabbix数据占用了8G空间**
二、查询Zabbix数据库里所有表大小
mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb,table_rows from information_schema.tables where table_schema='zabbix' order by total_mb desc;
+----------------------------+---------------+------------+
| table_name | total_mb | table_rows |
+----------------------------+---------------+------------+
| history_uint | 5487.29687500 | 56075683 |
| history | 4843.39062500 | 51787332 |
| trends_uint | 526.92187500 | 7440029 |
| history_str | 251.39062500 | 2393973 |
| trends | 215.87500000 | 2978883 |
| items | 6.21875000 | 10033 |
| events | 4.93750000 | 7922 |
| alerts | 4.67187500 | 5030 |
| items_applications | 2.35937500 | 11510 |
| triggers | 1.89062500 | 4359 |
| auditlog | 1.85937500 | 6803 |
| images | 1.53125000 | 138 |
| functions | 0.67187500 | 4746 |
| item_discovery | 0.57812500 | 3921 |
| graphs_items | 0.51562500 | 3773 |
| graphs | 0.50000000 | 1561 |
| auditlog_details | 0.42187500 | 2620 |
| event_recovery | 0.32812500 | 2936 |
| applications | 0.29687500 | 2345 |
| item_preproc | 0.29687500 | 3668 |
| application_template | 0.28125000 | 1989 |
| sessions | 0.23437500 | 1064 |
| hosts | 0.17187500 |