Sunday, May 22, 2016

Zabbix history and trends cleanup

Shut down the Zabbix server and frontend connections to the DB

If using MySQL, make sure auto_recalc is 1 otherwise you will have to analyze all these tables. The default value is 1.


CREATE TABLE history_new LIKE history;
CREATE TABLE history_log_new LIKE history_log;
CREATE TABLE history_str_new LIKE history_str;
CREATE TABLE history_text_new LIKE history_text;
CREATE TABLE history_uint_new LIKE history_uint;
CREATE TABLE trends_new LIKE trends;
CREATE TABLE trends_uint_new LIKE trends_uint;

ALTER TABLE trends RENAME trends_old;
ALTER TABLE trends_new RENAME trends;
ALTER TABLE trends_uint RENAME trends_uint_old;
ALTER TABLE trends_uint_new RENAME trends_uint;
ALTER TABLE history RENAME history_old;
ALTER TABLE history_new RENAME history;
ALTER TABLE history_log RENAME history_log_old;
ALTER TABLE history_log_new RENAME history_log;
ALTER TABLE history_str RENAME history_str_old;
ALTER TABLE history_str_new RENAME history_str;
ALTER TABLE history_text RENAME history_text_old;
ALTER TABLE history_text_new RENAME history_text;
ALTER TABLE history_uint RENAME history_uint_old;
ALTER TABLE history_uint_new RENAME history_uint;

DROP TABLE trends_old;
DROP TABLE trends_uint_old;
DROP TABLE history_old;
DROP TABLE history_log_old;
DROP TABLE history_str_old;
DROP TABLE history_text_old;
DROP TABLE history_uint_old;

delete from events;

That's all.

No comments:

Post a Comment