A few years ago, I wrote a couple of SQL queries that I put onto Github to clean up a Zabbix database. It’ll take items, triggers, events etc. that are no longer attached to a host, and remove them from the database.
This repo contains a few useful queries to cleanup old orphaned data in a Zabbix database. While Zabbix does Housekeeping, it does not clear orphaned data very well. Especially if you come from a long upgrade-line (1.x to 1.6 to 1.8 to 2.x), chances are your database is riddled with orphaned data that is consuming disk space.
I recently needed the files again after a few migrations, and they’ve served their purpose once again. They remain on Github for your consideration: Zabbix Orphaned Data Cleanup.
Hooray for open source! ;-)