I thought I would share this procedure I documented to purge old tasks and events in VirtualCenter. I initially opened a support case on this with Vmware because I wanted to get rid of the older tasks and events in VirtualCenter and there was nothing built into VC that would automatically do this. Vmware supports response was basically we don't support the maintenance, backup or data integrity of the VC database. They said you have to delete the data from the tables manually. So I did some research and put together this procedure in case anyone is interested. The tasks and event tables can get pretty large, mine had about 200,000 rows for just 4 ESX servers.
How can I purge old Event and Task data from VirtualCenter?
VirtualCenter does not support doing this directly, the only way you can do this by deleting directly from the database tables. It is strongly recommend to have a functional backup of the VC database before clearing these tables in case of an unforeseen problem. Also the the VC service must be stopped in order to avoid data corruption. This is not a supported procedure by Vmware but should be in my opinion, these tables can get pretty large in big environments as every single task and event is preserved in the database.
The tables where the data is stored are VPX_TASK (Tasks) and VPX_EVENT, VPX_EVENT_ARG (Events). The VPX_EVENT_ARG will usually have more rows then the VPX_EVENT table. This is because the VPX_EVENT table only has one row per event but the VPX_EVENT_ARG table can have multiple rows per event (The link between the 2 tables is the EVENT_ID column).
o Shutdown the VirtualCenter service
o Connect to the database server that is hosting the VC database with a SQL browser/client. You can use a free tool like WinSQL Lite (http://www.snapfiles.com/get/winsql.html) for this.
o To delete all data in the tables type: delete from VPX_TASK then delete from VPX_EVENT and then delete from VPX_EVENT_ARG and finally Commit
o Optionally you can do truncate table VPX_TASK then truncate table VPX_EVENT and then truncate table VPX_EVENT_ARG (Truncate is faster and does not use as much undo space as delete)
o To selectively delete data older then 30 days: delete from VPX_TASK where complete_time < sysdate - 30)
o To selectively delete data older then 30 days from VPX_EVENT and VPX_EVENT_ARG is trickier because VPX_EVENT_ARG does not have a date field and it tied to the events in VPX_EVENT by the Event_id field.
o First delete from the child table (VPX_EVENT_ARG): delete from vpx_event_arg where event_id in (select a.event_id from vpx_event_arg a, vpx_event b where a.event_id = b.event_id and create_time < sysdate - 30)
o Next commit the delete by typing Commit
o Then delete from the parent table (VPX_EVENT): delete from vpx_event where create_time < sysdate 30
o Finally commit again by typing Commit
o Start the VirtualCenter service