VMware

VMware vCenter Database Shrink Script

Whenever you’re using VMware vCenter in conjunction with Microsoft SQL Server Express Edition one day your database will run out of free space and vCenter Service will crash.

In VMware vCenter Server Settings, you can configure a period of time how long to retain old events and tasks in the database. Unfortunately, the cleanup process is a SQL Server Agent Job – remember: the free SQL Server Express Edition does not have an SQL Server Agent Service.

Many of my customers experienced this problem so I decided to write a simple batch script:

osql.exe -S VCSERVVCenter -U vpxadm -P vpxadm -d VCDB -Q "cleanup_events_tasks_proc"
osql.exe -S VCSERVVCenter -U vpxadm -P vpxadm -d VCDB -Q "DBCC SHRINKDATABASE(N'VCDB' )"
osql.exe -S VCSERVVCenter -U vpxadm -P vpxadm -d VCDB -Q "DBCC SHRINKFILE (N'VCDB' , 0, TRUNCATEONLY)"

You just need to modify the parameters, like database server, instance name, user, password e.g. to fit your environment.

Now you can just create a simple Windows Task using the Scheduled Task functionality to run this script periodically.

That’s it – your database won’t be run out of space anymore…

Leave Your Comment

Your Comment*

Your Name*
Your Webpage