Zabbix清理历史数据库,缩减表大小
zabbix 由于历史数据过大, 因此导致磁盘空间暴涨, 下面是解决方法步骤:
一、分析数据库:
1. 统计数据库中每个表所占的空间:
mysql> SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = 'zabbixdb'
ORDER BY (data_length + index_length) DESC;
+----------------------------+------------+
| Tables | Size in MB |
+----------------------------+------------+
| history_uint | 29417.00 |
| history | 8287.00 |
| events | 2367.67 |
| trends_uint | 1781.91 |
| event_recovery | 1211.33 |
| trends | 548.00 |
| history_str | 381.53 |
| history_text | 58.13 |
| alerts | 46.67 |
| problem | 31.06 |
| items | 25.23 |
| auditlog | 16.53 |
| items_applications | 6.20 |
| triggers | 5.31 |
| item_discovery | 5.30 |
| housekeeper | 3.52 |
| functions | 3.33 |
| graphs | 2.23 |
| graphs_items | 2.17 |
| item_preproc | 1.88 |
| auditlog_details | 1.69 |
| images | 1.53 |
| profiles | 0.80 |
| trigger_discovery | 0.42 |
| applications | 0.38 |
| application_template | 0.38 |
| trigger_depends | 0.33 |
| graph_discovery | 0.25 |
| hosts | 0.20 |
| item_condition | 0.16 |
| sessions | 0.14 |
| widget_field | 0.11 |
| dservices | 0.09 |
| sysmaps_elements | 0.09 |
| sysmaps | 0.08 |
| httptest | 0.08 |
| interface | 0.08 |
| mappings | 0.08 |
| hosts_templates | 0.08 |
| group_prototype | 0.06 |
| hostmacro | 0.06 |
| acknowledges | 0.06 |
| host_inventory | 0.06 |
| scripts | 0.06 |
| sysmaps_links | 0.06 |
| slides | 0.05 |
| maintenances_groups | 0.05 |
| users_groups | 0.05 |
| dashboard_usrgrp | 0.05 |
| sysmap_usrgrp | 0.05 |
| maintenances | 0.05 |
| dashboard_user | 0.05 |
| actions | 0.05 |
| opgroup | 0.05 |
| sysmap_user | 0.05 |
| httpstepitem | 0.05 |
| config | 0.05 |
| item_application_prototype | 0.05 |
| opcommand_hst | 0.05 |
| services_links | 0.05 |
| host_discovery | 0.05 |
| opcommand_grp | 0.05 |
| service_alarms | 0.05 |
| problem_tag | 0.05 |
| sysmap_element_trigger | 0.05 |
| task | 0.05 |
| drules | 0.05 |
| media | 0.05 |
| optemplate | 0.05 |
| slideshows | 0.05 |
| icon_mapping | 0.05 |
| screens | 0.05 |
| slideshow_usrgrp | 0.05 |
| sysmaps_link_triggers | 0.05 |
| icon_map | 0.05 |
| opmessage_usr | 0.05 |
| maintenances_windows | 0.05 |
| screen_usrgrp | 0.05 |
| application_prototype | 0.05 |
| httptestitem | 0.05 |
| opmessage_grp | 0.05 |
| slideshow_user | 0.05 |
| maintenances_hosts | 0.05 |
| screen_user | 0.05 |
| rights | 0.05 |
| hosts_groups | 0.05 |
| application_discovery | 0.05 |
| httptest_field | 0.03 |
| opmessage | 0.03 |
| event_tag | 0.03 |
| corr_condition_group | 0.03 |
| regexps | 0.03 |
| operations | 0.03 |
| group_discovery | 0.03 |
| users | 0.03 |
| corr_condition | 0.03 |
| opconditions | 0.03 |
| services_times | 0.03 |
| dashboard | 0.03 |
| sysmap_url | 0.03 |
| conditions | 0.03 |
| trigger_tag | 0.03 |
| interface_discovery | 0.03 |
| services | 0.03 |
| sysmap_shape | 0.03 |
| graph_theme | 0.03 |
| autoreg_host | 0.03 |
| corr_operation | 0.03 |
| opcommand | 0.03 |
| sysmap_element_url | 0.03 |
| escalations | 0.03 |
| media_type | 0.03 |
| httpstep_field | 0.03 |
| screens_items | 0.03 |
| httpstep | 0.03 |
| dhosts | 0.03 |
| widget | 0.03 |
| valuemaps | 0.03 |
| expressions | 0.03 |
| dchecks | 0.03 |
| groups | 0.03 |
| usrgrp | 0.03 |
| opinventory | 0.02 |
| proxy_history | 0.02 |
| proxy_dhistory | 0.02 |
| correlation | 0.02 |
| task_remote_command | 0.02 |
| proxy_autoreg_host | 0.02 |
| task_close_problem | 0.02 |
| corr_condition_tagvalue | 0.02 |
| task_acknowledge | 0.02 |
| globalvars | 0.02 |
| corr_condition_tagpair | 0.02 |
| ids | 0.02 |
| globalmacro | 0.02 |
| corr_condition_tag | 0.02 |
| history_log | 0.02 |
| timeperiods | 0.02 |
| task_remote_command_result | 0.02 |
| dbversion | 0.02 |
+----------------------------+------------+
140 rows in set (0.68 sec)
二、清理zabbix一周之前的历史数据:
!/bin/bash
User="zabbixuser"
Passwd="zabbixpass"
Date=`date -d $(date -d "-7 day" +%Y%m%d) +%s` #取7天之前的时间戳
$(which mysql) -u${User} -p${Passwd} -e "
use zabbixdb;
DELETE FROM history WHERE 'clock' < $Date;
optimize table history;
DELETE FROM history_str WHERE 'clock' < $Date;
optimize table history_str;
DELETE FROM history_uint WHERE 'clock' < $Date;
optimize table history_uint;
DELETE FROM history_text WHERE 'clock' < $Date;
optimize table history_text;
DELETE FROM trends WHERE 'clock' < $Date;
optimize table trends;
DELETE FROM trends_uint WHERE 'clock' < $Date;
optimize table trends_uint;
DELETE FROM events WHERE 'clock' < $Date;
optimize table events;
"
5.6以后用alter table table_name engine="InnoDB";
3、添加到系统计划任务:
#remove the zabbix mysql data before day's ago
* * /usr/local/script/clearzabbix.sh > /usr/local/script/clearzabbix.log
4、另:可以使用truncate命令直接清空数据库:
truncate table history;
truncate table history_uint;
truncate table history_str;
truncate table history_text;
truncate table trends;
truncate table trends_uint;
truncate table events;
如果想要删除表的所有数据,truncate语句要比 delete 语句快。
因为 truncate 删除了表,然后根据表结构重新建立它,而 delete 删除的是记录,并没有尝试去修改表。
不过truncate命令虽然快,却不像delete命令那样对事务处理是安全的。
因此,如果我们想要执行truncate删除的表正在进行事务处理,这个命令就会产生退出并产生错误信息。
Zabbix清理历史数据库,缩减表大小的更多相关文章
- zabbix清理监控历史mysql数据
问题描述: 今天同事说有个zabbix监控数据库历史数据越来越多了, 让我帮忙清一下,顺便熟悉练练手,做个笔记 zabbix监控运行一段时间以后,会留下大量的历史监控数据 zabbix数据库一直在增大 ...
- mysql单表大小的限制
mysql单表大小的限制一.MySQL数据库的MyISAM存储 引擎单表大小限制已经不是有MySQL数据库本身来决定(限制扩大到64pb),而是由所在主机的OS上面的文件系统来决定了.在mysql5. ...
- 查看mysql数据库表大小和最后修改时间
查看mysql数据库表相关信息如表大小.修改更新等信息,可以通过以下方式: 一 show table status like ’table_name‘ ; 二 在infortmation_sche ...
- mysql查看表大小
mysql查看表大小 一:命令 show table status like 'table_name'\G; mysql> show table status like 'x'\G; . row ...
- [记录]一则清理MySQL大表以释放磁盘空间的案例
一则清理MySQL大表以释放磁盘空间的案例 一.基本情况: 1.dbtest库554G,先清理st_online_time_away_ds(37G)表的数据,保留半年的数据: 1)删除的数据:sele ...
- PostgreSQL 查看单表大小
1. 在数据库中查单个表 select pg_size_pretty(pg_relation_size('table_name')); 2. 查出并按大小排序 SELECT table_schema ...
- postgresql-查看表大小
drop table tablesize create table tablesize( phone int) create table tablesize( phone text) create t ...
- SQL Server 游标运用:查看数据库所有表大小信息
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 方法一:运用游标 方法二:运用系统存储过程 方法三:拼接SQL ...
- Hash表的表大小
hash表的出现主要是为了对内存中数据的快速.随机的访问.它主要有三个关键点:Hash表的大小.Hash函数.冲突的解决. 这里首先谈谈第一点:Hash表的大小. Hash表的大小一般是定长的,如果太 ...
随机推荐
- java基础之异常。
异常: (1)异常:异常就是Java程序在运行过程中出现的错误. 异常由来:问题也是现实生活中一个具体事务,也可以通过java 的类的形式进行描述,并封装成对象.其实就是Java对不正常情况进行描述后 ...
- Redis源码解析:29事务
Redis通过MULTl,EXEC,WATCH,DISCARD等命令来实现事务(transaction)功能. 事务从MULTI命令开始,之后,该客户端发来的其他命令会被排队,客户端发来EXEC命令之 ...
- 【html、CSS、javascript-3】几个基本元素
HTML 元素指的是从开始标签到结束标签的所有代码. 开始标签 元素内容 结束标签 <h1> h标签用来表示标题 </h1> <p> p标签表示一个段落 </ ...
- textarea标签中多出的空格
//这么写才能被正确渲染 <textarea></textarea> //这样就会有空格 <textarea> </textarea> 不能换行,涨姿势
- php学习知识点框架
图片来源于知乎,感觉挺全面,通过查看可以更好的了解自己的薄弱知识点,大家共勉.
- laravel-admin 自定义导出excel功能,并导出图片
https://www.jianshu.com/p/91975f66427d 最近用laravel-admin在做一个小项目,其中用到了excel导出功能. 但是laravel-admin自带的导出功 ...
- 读书笔记--Head First 设计模式 目录
1.设计模式入门 2.观察者模式 3.装饰者模式 4.工厂模式 5.单件模式 6.命令模式 7.适配器模式与外观模式 8.模板方法模式 9.迭代器与组合模式 10.状态模式 11.代理模式 12.复合 ...
- mysql 索引优化 性能调优 锁
1 检查mysql 是否安装 rpm -qa|grep -i mysql 2 ntsysv 查看和设置开机启动列表 3 mysql 在 centos 上默认 的数据目录是 /var/lib/mysql ...
- hql 条件查询 返回空的一种情况
为何会出现查询为空,但是查询整个表没问题的情况呢? 这里是没有分清字符串和变量 原来写的是, String hql = "from ClientInfoModel where clientI ...
- CSS 定位 (Positioning)
CSS 定位 (Positioning) 属性允许你对元素进行定位. CSS 定位和浮动 CSS 为定位和浮动提供了一些属性,利用这些属性,可以建立列式布局,将布局的一部分与另一部分重叠,还可以完成多 ...