This repo contains a few useful queries for Zabbix database, mostly to cleanup old and/or orphaned data.
If you have a large database please note that these can take a while (read: a few hours is normal).
Use the queries above on your own risk. Take backups first.
Some scripts are Mysql or Postgresql specific, they're named *.my.sql and *.pg.sql, respectively. Pay attention.
The queries were tested against Zabbix 1.8 and 2.0. Apply with caution to other versions. Consider reporting the results, whether succesful or not.
user@host-$ mysql zabbix < check-orphaned-data.sql
user@host-$ mysql zabbix < delete-orphaned-data.sql
user@host-$ psql zabbix < delete-old-data.pg.sql
user@host-$ psql zabbix < delete-unused-data.sql
(Use stop-and-delete-email-alerts.sql if you're not interested in alert history)
user@host-$ sudo service zabbix-server stop
user@host-$ psql zabbix < stop-email-alerts.sql
user@host-$ sudo service zabbix-server start