Maintenance of MS SQL Database (vCentre): Difference between revisions
m (Sstrutt moved page Maintenance (vCentre) to Maintenance of MS SQL Database (vCentre)) |
(Reworked for SQL2008+) |
||
Line 1: | Line 1: | ||
== SQL | == Index Fragmentation == | ||
The vCenter database's indexes become fragmented over time, this is especially true of the performance statistic history tables, even if you have a [[[MS_SQL#Daily_Maintenance_Plan|Daily Maintenance Plan]] setup. | |||
=== Show Index Fragmentation === | |||
Run the script below in order to show fragmented tables, note that you need to replace the name of your vCenter database. | |||
<source lang="sql"> | |||
USE VCDB // Update with your database name | |||
SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName, | |||
ind.name AS IndexName, indexstats.index_type_desc AS IndexType, | |||
indexstats.avg_fragmentation_in_percent | |||
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats | |||
INNER JOIN sys.indexes ind | |||
ON ind.object_id = indexstats.object_id | |||
AND ind.index_id = indexstats.index_id | |||
WHERE indexstats.avg_fragmentation_in_percent > 60 | |||
ORDER BY indexstats.avg_fragmentation_in_percent DESC | |||
</source> | |||
=== Defragment Indexes === | |||
To defragment an individual table index use the following... | |||
<source lang="sql"> | |||
USE VCDB // Update with your database name | |||
ALTER IndexName ON TableName REORGANIZE | |||
</source> | |||
so for example | |||
<source lang="sql"> | |||
USE VCDB // Update with your database name | |||
ALTER INDEX PK_VPX_HIST_STAT4_106 ON VPX_HIST_STAT4_106 REORGANIZE | |||
</source> | |||
To generate a list of commands to run, use the following... | |||
<source lang="sql"> | |||
USE VCDB // Update with your database name | |||
SELECT 'ALTER INDEX ' + ind.name + ' ON ' + OBJECT_NAME(ind.OBJECT_ID) + ' REORGANIZE' | |||
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats | |||
INNER JOIN sys.indexes ind | |||
ON ind.object_id = indexstats.object_id | |||
AND ind.index_id = indexstats.index_id | |||
WHERE indexstats.avg_fragmentation_in_percent > 60 | |||
ORDER BY indexstats.avg_fragmentation_in_percent DESC | |||
</source> | |||
=== Pre SQL 2008 === | |||
''Summary of maintenance info from http://www.vmware.com/files/pdf/vc_microsoft_sql_server.pdf'' | ''Summary of maintenance info from http://www.vmware.com/files/pdf/vc_microsoft_sql_server.pdf'' | ||
=== Index Fragmentation === | ==== Show Index Fragmentation ==== | ||
'''This maintenance procedure can be performed inline (ie without stopping the DB or VirtualCenter)''' | '''This maintenance procedure can be performed inline (ie without stopping the DB or VirtualCenter)''' | ||
# Log into the SQL database using Query Analyser | # Log into the SQL database using Query Analyser | ||
Line 26: | Line 70: | ||
You may occasionally encounter a deadlock issue that causes the INDEXDEFRAG session to terminate. If the session terminates in this way, there is no adverse impact on the database, and the database continues running normally. You can issue the INDEXDEFRAG command again and the operation will resume from where it left off. | You may occasionally encounter a deadlock issue that causes the INDEXDEFRAG session to terminate. If the session terminates in this way, there is no adverse impact on the database, and the database continues running normally. You can issue the INDEXDEFRAG command again and the operation will resume from where it left off. | ||
=== Index Reindexing === | ==== Index Reindexing ==== | ||
'''This maintenance procedure can only be performed with the database offline, the VirtualCenter Server Service must be shutdown''' | '''This maintenance procedure can only be performed with the database offline, the VirtualCenter Server Service must be shutdown''' | ||
# Perform query to check the level of fragmentation (may take 2 mins or so to run). Create and execute the following query; | # Perform query to check the level of fragmentation (may take 2 mins or so to run). Create and execute the following query; | ||
Line 42: | Line 86: | ||
# Once complete, restart the VirtualCenter Server Service | # Once complete, restart the VirtualCenter Server Service | ||
== Migrate SQL2000 to SQL2005 == | |||
This should be fairly painless (so long as your DBA knows his stuff!). | This should be fairly painless (so long as your DBA knows his stuff!). | ||
Line 65: | Line 109: | ||
# Login using the VI Client and ensure everything looks good (clusters, ESX's, VM's, Alarms, Guest Customisations etc) | # Login using the VI Client and ensure everything looks good (clusters, ESX's, VM's, Alarms, Guest Customisations etc) | ||
==Other Tasks== | |||
Its also possible to delete old data from the database, this is achieved by running a script against the database, see http://kb.vmware.com/kb/1000125 for further info. | Its also possible to delete old data from the database, this is achieved by running a script against the database, see http://kb.vmware.com/kb/1000125 for further info. | ||
Revision as of 10:45, 1 November 2016
Index Fragmentation
The vCenter database's indexes become fragmented over time, this is especially true of the performance statistic history tables, even if you have a [[[MS_SQL#Daily_Maintenance_Plan|Daily Maintenance Plan]] setup.
Show Index Fragmentation
Run the script below in order to show fragmented tables, note that you need to replace the name of your vCenter database.
USE VCDB // Update with your database name
SELECT OBJECT_NAME(ind.OBJECT_ID) AS TableName,
ind.name AS IndexName, indexstats.index_type_desc AS IndexType,
indexstats.avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats
INNER JOIN sys.indexes ind
ON ind.object_id = indexstats.object_id
AND ind.index_id = indexstats.index_id
WHERE indexstats.avg_fragmentation_in_percent > 60
ORDER BY indexstats.avg_fragmentation_in_percent DESC
Defragment Indexes
To defragment an individual table index use the following...
USE VCDB // Update with your database name
ALTER IndexName ON TableName REORGANIZE
so for example
USE VCDB // Update with your database name
ALTER INDEX PK_VPX_HIST_STAT4_106 ON VPX_HIST_STAT4_106 REORGANIZE
To generate a list of commands to run, use the following...
USE VCDB // Update with your database name
SELECT 'ALTER INDEX ' + ind.name + ' ON ' + OBJECT_NAME(ind.OBJECT_ID) + ' REORGANIZE'
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats
INNER JOIN sys.indexes ind
ON ind.object_id = indexstats.object_id
AND ind.index_id = indexstats.index_id
WHERE indexstats.avg_fragmentation_in_percent > 60
ORDER BY indexstats.avg_fragmentation_in_percent DESC
Pre SQL 2008
Summary of maintenance info from http://www.vmware.com/files/pdf/vc_microsoft_sql_server.pdf
Show Index Fragmentation
This maintenance procedure can be performed inline (ie without stopping the DB or VirtualCenter)
- Log into the SQL database using Query Analyser
- Run up SQL Query Analyzer, and log into the SQL server
- Perform query to check the level of fragmentation (may take 2 mins or so to run). Create and execute the following query;
USE DB
(replace DB with whatever the database is called)GO
DBCC SHOWCONTIG (VPX_HIST_STAT,VPXII_HIST_STAT)
GO
- Check the query results for either of the following bad conditions
- Scan Density < 90%
- Logical Scan Fragmentation > 10%
- If required, perform defragmentation by running the following query (will take some time depending on level of fragmentation)
DBCC INDEXDEFRAG ('DB', 'VPX_HIST_STAT', 'VPXII_HIST_STAT')
GO
- Reheck the level of fragmentation using the following query (if Logical Scan Fragmentation is still > 30%, then may need to do reindex)
DBCC SHOWCONTIG (VPX_HIST_STAT,VPXII_HIST_STAT)
GO
- Update the statistics to continue providing accurate metrics, use the following query;
UPDATE STATISTICS VPX_HIST_STAT WITH FULLSCAN
GO
You may occasionally encounter a deadlock issue that causes the INDEXDEFRAG session to terminate. If the session terminates in this way, there is no adverse impact on the database, and the database continues running normally. You can issue the INDEXDEFRAG command again and the operation will resume from where it left off.
Index Reindexing
This maintenance procedure can only be performed with the database offline, the VirtualCenter Server Service must be shutdown
- Perform query to check the level of fragmentation (may take 2 mins or so to run). Create and execute the following query;
USE DB
GO
DBCC SHOWCONTIG (VPX_HIST_STAT,VPXII_HIST_STAT)
GO
- Check the query results for either of the following bad conditions
- Scan Density < 70%
- Logical Scan Fragmentation > 30%
- Stop the VirtualCenter Server Service
- Reindex the table by running this query;
DBCC DBREINDEX ('VPX_HIST_STAT', , 70)
GO
- Once complete, restart the VirtualCenter Server Service
Migrate SQL2000 to SQL2005
This should be fairly painless (so long as your DBA knows his stuff!).
Before you start, you must ensure the Virtual Centre is using a SQL Native Client driver to access the database (see VMware KB1003391)...
- Open up ODBC Data Source Administrator, and go to the System DSN tab
- Check that the driver you're using is SQL Native Client
- If not, you'll need to upgrade...
- Download from Microsoft and install SQL (see the VMware KB link above)
- Stop your Virtual Centre Server service
- Rename your existing DSN (eg append "old" to it)
- Create a new DSN using the new driver but otherwise exactly the same as the previous (the name MUST be the same)
- Restart the Virtual Centre Server service
- Login using the VI Client and ensure everything looks good (clusters, ESX's, VM's, Alarms, Guest Customisations etc)
To complete the migration...
- Stop the Virtual Centre Server service
- Backup the database (and log files) from your old SQL 2000 server
- Restore the database (and log files) to your new SQL 2005 server
- Ensure that your Virtual Centre's database account is the db_owner of the Virtual Centre database on SQL 2005 (as it was on the SQL2000 database)
- Change the ODBC DSN settings on the VC server so it points to the SQL 2005 server (just change the server name, if you need to specify a non-standard TCP port use
<SERVER>, <PORT>
rather than<SERVER>:<PORT>
) - Restart the Virtual Centre Server service
- Login using the VI Client and ensure everything looks good (clusters, ESX's, VM's, Alarms, Guest Customisations etc)
Other Tasks
Its also possible to delete old data from the database, this is achieved by running a script against the database, see http://kb.vmware.com/kb/1000125 for further info.