How to Shrink vCenter Database
This articles describes how to purge old data from your vCenter DB and shrink vCenter database files in order to free up space; running out of disk space brings a whole host of potential problems with complete outage in a worst case scenario.
This example shows a Windows 2008 v5.5 vCenter server running a MSSQL database and is broken down into five procedures:
- Stop the vCenter Server service – very important otherwise major corruption will occur!
- Set the retention policy on your vCenter server – optional
- Purge old data from your existing database using MS SQL Server Manager
- Shrink database using MS SQL Server Manager
- Restart the vCenter Server service
As with all operations of this nature, a full backup / snapshot of your database is advised before proceeding!
Stop vCenter Service
- Open your services configuration pane in your favourite server management console snap-in, locate the VMware VirtualCenter Server service, right-click and choose “Stop” – this may take a few minutes to complete.
Set Retention Policy
- In the vSphere client, click “Administration” and then “Database Retention Policy” in the newly-opened window.
- Here you can select the length of time your logs will be kept for before an automatic purge is executed.
Purge Old Data
Once you have set your retention policy you can purge your old data.
- Open a new query in MS SQL Server Manager and paste in the contents of the sql script on the link below.
- Click “Execute” to run the script. By default, the script will only count the rows of data which can be deleted – do this as a first dry run before committing to deletion.
- Once you have performed the above test, change the value of DELETE_DATA to 1 and then click “Execute” – the script may return a “non-updateable” error which can be safely ignored.
- Download the script: VCDB_table_cleanup_MSSQL
Shrink vCenter Database
- Open MS SQL Server Manager and locate the database (default: VIM_VCDB) in Object Explorer, right-click -> Tasks -> Shrink -> Database]
Restart vCenter Service
- In the services configuration pane, right-click “VMware VirtualCenter Server” and choose “Start” – again this may take a minute or two to complete. When done, test that you can log Back in with either the web gui or vSphere client.