Maintenance Plans

Overview

The DB maintenance routines are based on the well known scripts set of Ola Hallengrenopen in new window.
For the MVP the solution will be implemented with fixed scheduling and covering all the database.

Integrity check

Details about syntax and options can be found under: https://ola.hallengren.com/sql-server-integrity-check.html.
The jobs are implemented with the following command.

System databases

EXECUTE dbo.sp_DatabaseIntegrityCheck
@Databases = 'SYSTEM_DATABASES',
@CheckCommands = 'CHECKDB',
@LogToTable = 'Y'
Use in Job: SCS_SysDbIntegrity

User databases

EXECUTE dbo.sp_DatabaseIntegrityCheck
@Databases = 'USER_DATABASES',
@CheckCommands = 'CHECKDB',
@LogToTable = 'Y'
Use in Job: SCS_UserDbIntegrity

Index and statistics maintenance

Details about syntax and options can be found under: https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html.
In the reindexing job we include an additional update statistics for modified rows only.
The sort operations are redirected to the tempDB as we have a dedicated drive. Furthermore we put a time limit of 5 hours.

Reindexing

EXECUTE dbo.sp_IndexOptimize
@Databases = 'USER_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30,
@SortInTempdb = 'Y',
@MaxDOP = 0,
@OnlyModifiedStatistics = 'Y',
@TimeLimit = 18000,
@LogToTable = 'Y'
Use in Job: SCS_Reindexing_Statistics

Update Statistics

EXECUTE dbo.sp_IndexOptimize
@Databases = 'USER_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = NULL,
@FragmentationHigh = NULL,
@UpdateStatistics = 'ALL',
@LogToTable = 'Y'
Use in Job: SCS_AllUserDbUpdateStats

Cleanup

The cleanup is implemented at two level:

  • Table T_CommandLog: job SCS_CommandLogCleanup to clean up entries older than 30 days
  • Log files: job SCS_CleanupFiles to clean up files older than 30 days

The execution is logged at file level.

Objects list

In the scs_AdminDB the following objects are configured:

NameTypeOriginal nameDescription
T_CommandLogtableCommandLogLogging table
sp_CommandExecuteprocedureCommandExecuteSP used for command executing
sp_DatabaseIntegrityCheckprocedureDatabaseIntegrityCheckCheck DB
sp_IndexOptimizeprocedureIndexOptimizeReindexing and update statistics

Job list and frequency

The maintenance will be implemented through SQL Agent scheduled jobs.

MaintenanceDB'sJobScheduling
Integrity ChecksSystem DB'sSCS_SysDbIntegrityWeekly, Sunday 00:00 am
Integrity ChecksUser DB'sSCS_UserDbIntegrityWeekly, Sunday 00:15 am
Index and update statistics modified onlyUser DB'sSCS_AllUserDbIndexingWeekly, Sunday 01:00 am
Update statistics allUser DB'sSCS_AllUserDbUpdateStatsWeekly, Wednesday 01:00 am
Clean up command log tablen/aSCS_CommandLogCleanupDaily 04:00 am
Last Updated: