2. Objectives Make informed decisions about the maintenance that must be performed within SQL Server. Enhance Proactive Administration by receiving Notifications for Job Failures and Alerts. Ensure consistency across your environment by performing routine system maintenance.
3. Agenda Configuring Database Mail Creating Alerts Creating An Administrative Database Configuring Maintenance Jobs Maintenance Considerations When Upgrading a Database
5. Configuring Database Mail Enable Database Mail Create Profile Create Account Create Operator Enable Database Mail in SQL Server Agent Enable Fail-Safe Operator
6. Creating Alerts Automated response to a predefined event Severity Codes Fatal Errors19-25 Specific Error Numbers Error 825 – Severity 10 http://sqlskills.com/BLOGS/PAUL/post/A-little-known-sign-of-impending-doom-error-825.aspx
7. Creating Alerts (Cont) Non Fatal ErrorsSELECT * FROM sys.messagesWHERE language_id = 1033 ANDis_event_logged = 1 AND severity < 19
8. Why Do You Need An Administrative Database? Provide central location for Administrative Tables, Functions, and Procedures Track Database Sizes for Capacity Planning Store DMV Output Holds the Nums or TallyTable http://www.sqlservercentral.com/articles/TSQL/62867/
9. What Maintenance Jobs Should You Be Running? Cycle the Error Log Make sure to increase the number of log files first. sp_cycle_errorlog Cleanup the Backup History Be careful if you havea lot of history. sp_delete_backuphistory Cleanup Mail History sysmail_delete_mailitems_sp sysmail_delete_log_sp
10. Maintenance Jobs (Cont) Update Statistics sp_updatestats Index Maintenance > 5% and < = 30% REORGANIZE > 30% REBUILD
11. Maintenance Jobs (Cont) Collect Database Sizes Check for long running jobs http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=AgentLongRunning&referringTitle=Home Check Database Integrity DBCC CHECKDB Backups Script Restore to file using backup history tables http://www.mssqltips.com/tip.asp?tip=1611 Make sure each job has an output file
13. Maintenance Considerations When Upgrading a Database Change Database Compatibility Level ALTER DATABASE [DatabaseName] SET COMPATIBILITY_LEVEL = 100 Check the integrity of the objects in your database DBCC CHECKDB ([DatabaseName]) WITH DATA_PURITY Correct Row and Page Counts DBCC UPDATEUSAGE ([DatabaseName]) Set the page verification method to CHECKSUM ALTER DATABASE [DatabaseName] SET PAGE_VERIFY CHECKSUM WITH NO_WAIT Update Statistics With Full Scan sp_msforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN'
What works for one server may not be the best for another. You should be aware of the system maintenance that needs to be performed and how the decisions you make will impact your SQL Server.
--The ALTER DATABASE statement replaces the sp_dbcmptlevel procedureALTER DATABASE [DatabaseName] SET COMPATIBILITY_LEVEL = 100--Adding the DATA_PURITY option causes the CHECKDB command to look for --column values that are invalid or out of range. Any database that was --created in SQL Server 2005 or later will include the DATA_PURITY check by default, --but if the database is being upgraded from an earlier version, you must run the --command with the DATA_PURITY option at least once and fix any issues. DBCC CHECKDB ([DatabaseName]) WITH DATA_PURITY--The DBCC UPDATEUSAGE command corrects inaccurate row and page counts for tables and indexes.DBCC UPDATEUSAGE ([DatabaseName])--When the CHECKSUM option is enabled, a checksum of the whole page is computed and stored in --the page header when the page is written to disk. When the page is read from disk, the --checksum is recalculated and compared with the value in the header.ALTER DATABASE [DatabaseName] SET PAGE_VERIFY CHECKSUM WITH NO_WAIT--Updating the statistics after the upgrade allows the database engine to take advantage of --the enhancements made in SQL Server 2008 to optimize query performance. The statistics --that reside in the database were created with an earlier version of SQL Server. --By recreating them with SQL Server 2008; you are allowing SQL Server to create more --intelligent statistics to work with. sp_msforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN'