Skip to content

Instantly share code, notes, and snippets.

@p0vidl0
Forked from edtjones/zabbix_cleanup.sql
Last active September 22, 2018 03:15
Show Gist options
  • Save p0vidl0/3b6ea21b4ca6c9b23ec576269ba24202 to your computer and use it in GitHub Desktop.
Save p0vidl0/3b6ea21b4ca6c9b23ec576269ba24202 to your computer and use it in GitHub Desktop.
Clean up zabbix database
SET @history_interval = 3;
SET @trends_interval = 90;
DELETE FROM alerts WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE alerts ENGINE=INNODB;
DELETE FROM acknowledges WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE acknowledges ENGINE=INNODB;
DELETE FROM events WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE events ENGINE=INNODB;
DELETE FROM history WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE history ENGINE=INNODB;
DELETE FROM history_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE history_uint ENGINE=INNODB;
DELETE FROM history_str WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE history_str ENGINE=INNODB;
DELETE FROM history_text WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE history_text ENGINE=INNODB;
DELETE FROM history_log WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@history_interval * 24 * 60 * 60);
ALTER TABLE history_log ENGINE=INNODB;
DELETE FROM trends WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
ALTER TABLE trends ENGINE=INNODB;
DELETE FROM trends_uint WHERE (UNIX_TIMESTAMP(NOW()) - clock) > (@trends_interval * 24 * 60 * 60);
ALTER TABLE trends_uint ENGINE=INNODB;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment