Purge and Shrink vCenter Database

Purge and Shrink vCenter Database

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:

  1. Stop the vCenter Server service – very important otherwise major corruption will occur!
  2. Set the retention policy on your vCenter server – optional
  3. Purge old data from your existing database using MS SQL Server Manager
  4. Shrink database using MS SQL Server Manager
  5. 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.

stop vcenter service

Set Retention Policy

  • In the vSphere client, click “Administration” and then “Database Retention Policy” in the newly-opened window.

vcenter settings

  • Here you can select the length of time your logs will be kept for before an automatic purge is executed.

db retention policy settings

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.

open a new query

  • 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.

execute script

  • 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]

shrink vcenter 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.

start vcenter service

 

 

 

2 thoughts on “Purge and Shrink vCenter Database

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.