Purging old data from the database used by vCenter Server (1025914)
- You cannot log in to vCenter Server
- VMware VirtualCenter Server service may start and stop immediately.
- Microsoft SQL Event log reports the error:
Could not allocate space for object 'dbo.VPX_EVENT'.'VPXI_EVENT_USERNAME' in database 'VCDB' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
- The scripts attached to this article are intended for execution by database administrators (DBAs) who are experienced with using database client tools to execute SQL commands. The purpose of the scripts is to delete data.
- VMware recommends that you stop the VMware VirtualCenter Server service and take a full, reliable backup of your database before attempting this process.
- If you are using SQL 2005 Express, you may need to download and install Microsoft SQL Server Management Studio Express.
- SQL Express 2005/2008 (vCenter Server 5.x is bundled with SQL Express 2008) supports a maximum of 5 hosts and 50 virtual machines. If your environment exceeds these thresholds, you must upgrade your database to SQL Standard edition.
- These scripts delete rows, in batches, from designated tables in the vCenter Server database. By default, however, it only reports the number of rows that is deleted. To actually delete data, a configuration parameter within the script must be modified. This is a safety precaution. See the comments in the heading of the script for details. Diagnostic messages are printed that summarize the operations.
- The database transaction log may fill up during this procedure if sufficient disk space is not available. For SQL Server, if the required disk space cannot be made available, one option is to utilize the simple recovery model on the database for the duration of this operation.
- The attached script for the Oracle database is applicable only to vCenter Server 5.0 and earlier.
Purge the tasks and event tables
- Connect to
Servername\SQL Databaseand log in with the appropriate credentials.
- Click databases to expand and select VIM_VCDB > Tables.
Note: By default, the vCenter Server database is named
VIM_VCDB, unless it was renamed during initial creation.
- Right-click the dbo.VPX_PARAMETER table and click Open.
Note: If you are using SQL Server 2008, right-click the dbo.VPX_PARAMETER table and click Edit Top 200 Rows.
- Modify event.maxAge to 30 and the event.maxAgeEnabled value to true.
- Modify task.maxAge to 30 and the task.maxAgeEnabled value to true.
Note: To improve the time of the data cleanup, run the preceding steps in several intervals:
- Ensure to keep the default value of event.maxAge and task.maxAge.
- Perform step 6 to run the cleanup.
- Reduce the event.maxAge and task.maxAge value by 60 and run the cleanup.
- Repeat the steps a-c until the value is reached to 30 for the final cleanup process.
- Run the built-in stored procedure:
- Go to VIM_VCDB > Programmability > Stored Procedures.
- Right-click dbo.cleanup_events_tasks_proc and select Execute Stored Procedure.
This purges the data from the vpx_event, vpx_event_arg, and vpx_task tables based on the date specified for maxAge.
- When purging is successfully completed, close the SQL Management Studio and start the VMware Virtual Center Server service.
- Ensure that the default Statistics Level is set to 1:
- Using the vSphere Client, log in to vCenter Server as an administrator.
- Go to Administration > vCenter Server Settings > Statistics.
- Under Statistics Intervals, ensure the Statistics Level column is set to 1.
- To change the value, select the Interval Duration, click Edit and select Level 1 from the list.
- The execution of
dbo.cleanup_events_tasks_procmay take a long period of time depending on the database size.
- The operation may fail due to the transaction logs being filled up at multiple intervals based on the data to be purged. You must shrink the Transaction logs when required and run
Truncate the event and tasks table
alter table VPX_EVENT_ARG drop constraint FK_VPX_EVENT_ARG_REF_EVENT, FK_VPX_EVENT_ARG_REF_ENTITY
alter table VPX_ENTITY_LAST_EVENT drop constraint FK_VPX_LAST_EVENT_EVENT
truncate table VPX_TASK
truncate table VPX_ENTITY_LAST_EVENT
truncate table VPX_EVENT
truncate table VPX_EVENT_ARG
alter table VPX_EVENT_ARG add constraint FK_VPX_EVENT_ARG_REF_EVENT foreign key(EVENT_ID) references VPX_EVENT (EVENT_ID) on delete cascade,
constraint FK_VPX_EVENT_ARG_REF_ENTITY foreign key (OBJ_TYPE) references VPX_OBJECT_TYPE (ID)
alter table VPX_ENTITY_LAST_EVENT add constraint FK_VPX_LAST_EVENT_EVENT foreign key(LAST_EVENT_ID)
references VPX_EVENT (EVENT_ID) on delete cascade
Disclaimer: VMware is not responsible for the reliability of any data, opinions, advice, or statements made on third-party websites. Inclusion of such links does not imply that VMware endorses, recommends, or accepts any responsibility for the content of such sites.
Using the following Microsoft SQL Studio options do not help with purging the VPX_EVENT and VPX_TASK table:
- Purging the old data
- Truncating tables
- Shrinking the logs and database
- Recreating Roll up jobs
- Reducing the size of the vCenter Server database when the rollup scripts take a long time to run (1007453)
- Selective deletion of tasks, events, and historical performance data in vSphere 5.x and 6.x (2110031)