AUTOMATING ROUTINE
MAINTENANCE
Ken Simmons
Objectives
1. Make informed decisions about the maintenance that must be performed within SQL Server.
2. Enhance Proactive Administration by receiving Notifications for Job Failures and Alerts.
3. Ensure consistency across your environment by performing routine system maintenance.
Agenda
Configuring Database Mail Creating Alerts Creating An Administrative
Database Configuring Maintenance Jobs Maintenance Considerations
When Upgrading a Database
Why Do We Need To Perform Routine Maintenance?
Configuring Database Mail
Enable Database Mail Create Profile Create Account Create Operator Enable Database Mail
in SQL Server Agent Enable Fail-Safe
Operator
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
Creating Alerts (Cont) Non Fatal ErrorsSELECT * FROM sys.messagesWHERE language_id = 1033 AND is_event_logged = 1 AND severity < 19
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.c
om/articles/TSQL/62867/
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
Maintenance Jobs (Cont)
Update Statistics sp_updatestats
Index Maintenance > 5% and < = 30%
REORGANIZE > 30% REBUILD
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
Maintenance Jobs(Cont)
Generate SQL Agent Job Schedule Report http://www.mssqltips.com/tip.asp?ti
p=1622
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'
Questions?
Links
Preproduction Checklisthttp://www.sqlservercentral.com/
articles/Administration/64732/
Blog: http://cybersql.blogspot.com/ Email: [email protected] Linked In:
http://www.linkedin.com/in/kensimmons Twitter: http://twitter.com/kensimmons