Hubzilla 12 has delivered two new maintenance scripts.
util/cleanup_dead_sites and
util/cleanup_deleted_hublocs. The name of the scripts pretty much explains it all but there are some hidden gems though.
Cleaning up dead sites:util/cleanup_dead_sites will do a dry run only
util/cleanup_dead_sites delete will actually delete stuff from your DB
util/cleanup_dead_sites delete 1000 will slate 1000 sites for cleanup (default is 100)
Cleaning up deleted hublocs:util/cleanup_deleted_hublocs will do a dry run only
util/cleanup_deleted_hublocs delete will actually delete stuff from your DB
util/cleanup_deleted_hublocs delete 1000 will slate 1000 hublocs for cleanup (default is 100)
If you have an old site you will need to run the script many times until all items will be cleaned up. Make sure to not slate too many sites/hublocs in one go to not overstrain your server.
Good luck!