The Ultimate Maintenance Plan By Edward Roepe Perimeter DBA, LLC
About Me Over 25 years experience in databases I have been working with SQL Server since version 4.21 Worked as employee and consultant on some of the largest SQL database installations in US Experience in many different industries Experience in very large databases, high transaction systems, and high availability Microsoft Certified Started consulting firm in 2014 in the Atlanta area
Agenda Discuss the Microsoft Built-in Maintenance Plans Discuss the Ola Hallengren Maintenance Solution Discuss other items that should be part of a maintenance plan Discuss some typical maintenance plans Discuss alerts Demo
Goals of a maintenance solution Lights out Reliable Flexible Proactive alerting Robust Report errors
Microsoft Maintenance Solution Integrity Check Index Maintenance Update Statistics Database Backups
Starting the Microsoft Maintenance Plan
Microsoft Solution – Pros & Cons Simple to setup. Just run the wizard Designed for basic servers Provided by Microsoft Cons Sometimes with older versions you have to have the same version of SSMS as SQL to create/modify Index maintenance does all indexes Statistics maintenance does all statistics
Ola Hallengren Maintenance Solution Written by Ola Hallengren DBA in Saxo Bank, a Danish investment bank Microsoft MVP – SQL Server https://ola.hallengren.com/ Consists of SQL Server Backups SQL Server Integrity Check SQL Server Index and Statistics Maintenance Log of each step into table
Installing the solution Download the scripts Create database to contain stored procedures and log table (suggest DBAUtility) Install the stored procedures Create the scheduled jobs Modify the scheduled jobs as needed Add additional maintenance functions
How it works Stored Procedure is called for each function (index, backup, stats, etc.) Start of each function/step is logged into table End of each function/step is logged into table Return code and any errors are returned to calling program
Backups – Common Options Backup location Databases to include or exclude Full Backup Differential Backup Log Backup Verify backup Number of hours to cleanup old backups
Backups – Advanced Options Compression Call to 3rd party backup programs (Quest Litespeed, Idera SQL Safe, etc.) Perform a full backup if log is taken and no full backup exists Copy Only – For snapshots. Take backup without disrupting last full backup Backup to multiple files at the same time Perform Verify and Checksum Specify cleanup BEFORE or AFTER backup
Full Backups - Example EXEC [DBAUtility].[dbo].[DatabaseBackup] @Databases = 'ALL_DATABASES', @Directory = 'E:\SQLServerBackups', @BackupType = 'FULL', @Verify = 'N', @CleanupTime = '192', @CleanupMode = 'AFTER_BACKUP', @Compress = 'Y', @CopyOnly = 'N', @ChangeBackupType = 'N', @CheckSum = 'N', @LogToTable = 'Y'
Log Backups - Example EXEC [DBAUtility].[dbo].[DatabaseBackup] @Databases = 'ALL_DATABASES', @Directory = 'E:\SQLServerBackups', @BackupType = 'LOG', @Verify = 'N', @CleanupTime = 192, @CleanupMode = 'AFTER_BACKUP', @Compress = 'Y', @CopyOnly = 'N', @ChangeBackupType = 'Y', @CheckSum = 'N', @LogToTable = 'Y'
Index & Statistics – Basic Options Databases to include or exclude Tables to include or exclude Define three fragmentation groups Low = Zero to first threshold Medium = First threshold to second threshold High = Second threshold to infinity Define actions for each group (example) Low = No action Medium = Index reorganize High = Index Rebuild:
Index & Statistics – Advanced Options Specify the order for performing indexing (Online, reorganize, rebuild, etc.) Program will automatically select available options based on version and edition Specify MAXDOP or SORT_IN_TEMPDB Specify FILLFACTOR and PADINDEX Specify UpdateStatistics or OnlyModifiedStatistics Specify the time limit (to prevent running into production)
Index & Statistics - Example EXEC [DBAUtility].[dbo].[IndexOptimize] @Databases = 'All_DATABASES’, @FragmentationLow = NULL, @FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE’, @FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE’, @FragmentationLevel1 = 5, @FragmentationLevel2 = 30, @MaxDOP = 1, @SortInTempdb = 'Y’, @LOBCompaction = 'N’, @UpdateStatistics = 'ALL’, @OnlyModifiedStatistics = 'Y’, @LogToTable = 'Y'
Integrity Check – Basic Options Specify database to include or exclude Specify PHYSICAL_ONLY or NOINDEX
Integrity Check - Example EXEC [DBAUtility].[dbo].[DatabaseIntegrityCheck] @Databases = 'ALL_DATABASES', @LogToTable = 'Y'
Ola Hallengren – Pros & Cons Very powerful. A simple command can do 1000s of steps Program automatically deals with version and edition so you can roll out the same plan to multiple different servers The index & statistics program is very sophisticated and will only do what is needed Cons Some learning curve on learning the commands and syntax The supplied maintenance jobs use CMD mode. Using the T-SQL mode is much simpler
Tricks to rolling out maintenance jobs Use CMS or Registered servers to deploy to multiple servers Create first set of jobs, script the jobs, and then deploy to other servers. Will need to remove the ID of the schedule Write script to dynamically calculate the location of the SQL log subdirectory Prefix all maintenance jobs with a unique identifier. I use “DBA –” Setup Database Mail, operator and alerts on all jobs
Other Maintenance Items Recycle the SQL Log daily (retention 15 to 30 days) Cleanup the job history table in MSDB (retention 30 days) Cleanup the backup history table in MSDB (retention 30 days) Cleanup to email history table in MSDB (retention 30 days) Cleanup the TXT files in the SQL Log directory (retention 30 days) Cleanup the Ola log table (retention 7 to 30 days) Cleanup the Syspolicy table Setup alerts
Alerts – Script 3011 - Part 1 Error 0823 - Hardware or System Problems Error 0824 - Logical Page Consistency I/O Error Error 0825 - Read Operation I/O Error Error 0832 - Page Corruption In Memory Error 1105 - Filegroup Full Error 1205 - Deadlock Detected Error 9001 - Database Log Not Available Error 9002 - Transaction Log Full Error 9003 - Invalid LSN in Transaction Log Error 9004 - Error With Transaction Log Error 9100 - Index Corruption
Alerts – Script 3011 - Part 2 Severity 16 - Miscellaneous User Error Severity 17 - Insufficient Resources Severity 18 - Nonfatal Internal Error Severity 19 - Fatal Error in Resource Severity 20 - Fatal Error in Current Process Severity 21 - Fatal Error in Database Processes Severity 22 - Table Integrity Suspect Severity 23 - Database Integrity Suspect Severity 24 - Hardware Error Severity 25 - Unexpected Fatal Error
Suggested Maintenance Plans Task Small Medium Large Integrity Check Daily Daily or Weekly Weekly Update indexes Update statistics Daily or Hourly Full Backups Differential Backups None Log Backups Hour 15 min or hour 15 min or less Cleanup tasks
Demo of OLA install How to download software https://ola.hallengren.com/ How to install stored procedures and jobs Change the default database Create jobs option Backup directory option No schedule on jobs
Demo of “DBA” Jobs How to install stored procedures (Script 3023) How to install scheduled jobs (Script 3022) Show Daily DB Maintenance Show Daily Full Backups Show Daily Log Backups Show Daily Syspolicy Purge Show Daily System Cleanup Show Alerts
Summary Tour of Microsoft maintenance solution Tour of Ola Hallengren maintenance solution Other maintenance items Setup alerts Suggested maintenance plans Demo of Ola install Demo of DBA jobs install
Q&A Contact Information Edward Roepe Perimeter DBA, LLC 4780 Ashford Dunwoody Road, Suite 337 Dunwoody GA 30338 (678) 575-6146 Edward@PerimeterDBA.com www.PerimeterDBA.com Our Services Health Checks Security Checks Performance Tuning High Availability Disaster Recovery Managed Services Business Intelligence Development Services