Automating routine maintenance

1,913 views
1,804 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,913
On SlideShare
0
From Embeds
0
Number of Embeds
116
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 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'
  • Automating routine maintenance

    1. 1. Automating Routine Maintenance<br />Ken Simmons<br />
    2. 2. Objectives<br />Make informed decisions about the maintenance that must be performed within SQL Server.<br />Enhance Proactive Administration by receiving Notifications for Job Failures and Alerts.<br />Ensure consistency across your environment by performing routine system maintenance.<br />
    3. 3. Agenda<br />Configuring Database Mail<br />Creating Alerts<br />Creating An Administrative Database<br />Configuring Maintenance Jobs<br />Maintenance Considerations When Upgrading a Database<br />
    4. 4. Why Do We Need To Perform Routine Maintenance?<br />
    5. 5. Configuring Database Mail<br />Enable Database Mail<br />Create Profile <br />Create Account<br />Create Operator<br />Enable Database Mail in SQL Server Agent<br />Enable Fail-Safe Operator<br />
    6. 6. Creating Alerts<br />Automated response to a predefined event<br />Severity Codes <br />Fatal Errors19-25<br />Specific Error Numbers<br />Error 825 – Severity 10<br />http://sqlskills.com/BLOGS/PAUL/post/A-little-known-sign-of-impending-doom-error-825.aspx<br />
    7. 7. Creating Alerts (Cont)<br />Non Fatal ErrorsSELECT * FROM sys.messagesWHERE language_id = 1033 ANDis_event_logged = 1 AND severity < 19<br />
    8. 8. Why Do You Need An Administrative Database?<br />Provide central location for Administrative Tables, Functions, and Procedures<br />Track Database Sizes for Capacity Planning<br />Store DMV Output<br />Holds the Nums or TallyTable<br />http://www.sqlservercentral.com/articles/TSQL/62867/<br />
    9. 9. What Maintenance Jobs Should You Be Running?<br />Cycle the Error Log<br />Make sure to increase the number of log files first.<br />sp_cycle_errorlog<br />Cleanup the Backup History<br />Be careful if you havea lot of history.<br />sp_delete_backuphistory<br />Cleanup Mail History<br />sysmail_delete_mailitems_sp<br />sysmail_delete_log_sp<br />
    10. 10. Maintenance Jobs (Cont)<br />Update Statistics<br />sp_updatestats<br /> Index Maintenance<br />> 5% and < = 30% REORGANIZE<br />> 30% REBUILD<br />
    11. 11. Maintenance Jobs (Cont)<br />Collect Database Sizes<br />Check for long running jobs<br />http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=AgentLongRunning&referringTitle=Home<br />Check Database Integrity<br />DBCC CHECKDB<br />Backups<br />Script Restore to file using backup history tables<br />http://www.mssqltips.com/tip.asp?tip=1611<br />Make sure each job has an output file<br />
    12. 12. Maintenance Jobs(Cont)<br />Generate SQL Agent Job Schedule Report<br />http://www.mssqltips.com/tip.asp?tip=1622<br />
    13. 13. Maintenance Considerations When Upgrading a Database<br />Change Database Compatibility Level<br />ALTER DATABASE [DatabaseName] SET COMPATIBILITY_LEVEL = 100<br />Check the integrity of the objects in your database<br />DBCC CHECKDB ([DatabaseName]) WITH DATA_PURITY<br />Correct Row and Page Counts<br />DBCC UPDATEUSAGE ([DatabaseName]) <br />Set the page verification method to CHECKSUM<br />ALTER DATABASE [DatabaseName] SET PAGE_VERIFY CHECKSUM WITH NO_WAIT<br />Update Statistics With Full Scan<br />sp_msforeachtable 'UPDATE STATISTICS ? WITH FULLSCAN'<br />
    14. 14. Questions?<br />
    15. 15. Links<br /><ul><li>Preproduction Checklist
    16. 16. http://www.sqlservercentral.com/articles/Administration/64732/
    17. 17. Blog: http://cybersql.blogspot.com/
    18. 18. Email: cyberjunkyks@yahoo.com
    19. 19. Linked In: http://www.linkedin.com/in/kensimmons
    20. 20. Twitter: http://twitter.com/kensimmons</li>

    ×