Download presentation
Presentation is loading. Please wait.
1
SQL SERVER MAINTENANCE PLANS Kat Long Kmeadows@xtivia.com @KatSQL www.xtivia.com
2
BASIS OF PRESENTATION Maintenance plans are used as a starting point to insure that your systems are: backed up, performing at optimal speed, and data is consistent. There are many ways to implement what we discuss today, this is just to show the basics that every system should have. DBA since 1998 SQL Server 6.5 and greater Oracle 8i, 9i, 11g R2 Worked in the following industries: -Manufacturing -.coms -Government -Consulting
3
ASSUMPTIONS These tips are based on common occurrences I have witnessed, your mileage may very. If you have a question feel free to stop me and ask. I may have to move past them depending on time, but we can touch base after the session. Email me - It’s okay! - kmeadows@xtivia.comkmeadows@xtivia.com Please help me make this presentation better! If you have suggestions, please review the session. Also, if you enjoy the session, please review it. Lets get started…
4
GENERAL OVERVIEW Routine tasks to help keep your database happy, well maybe... Database Backups Integrity Checks Exec Agent jobs or T-SQL scripts Rebuild or Reorganize Indexes Update Stats Clean up Tasks Log results Shrink database
5
TO USE OR NOT TO USE...
6
BASIC SETUP Meaningful Name Description Manage Connections Reporting and logging -Location of Log -Email of log Sub plan Meaningful Naming Adding Annotations
7
DEMO Demo 1 - Basic Setup for Maintenance Plans
8
BACKUPS Before creating the maintenance plan what should you consider? -What is your time to recover -What is your loss of data -Databases Size (sp_spaceused) -Recovery Mode -Off Peak hours -Frequency of data updates -Data changes, across all tables or only a couple
9
BACKUPS Types of Backups -Full, Differential, Transaction log -All System, User databases, specific database -Database or File and File groups -Disk, Tape or URL (new in SQL 2014) -Backups to more than one location -Overwrite or append to the backup file
10
BACKUPS Have it create a folder for every database Set the backup file extension Set when the backup set will expire -Delete backup file does not take this date into account Verify the Backup file integrity -RESTORE VERIFY ONLY Compress or not compressed backups New for SQL 2016 -Perform Checksum -Continue on Error -Block Size -Max Transfer Size
11
DEMO Demo 2 - Backup and Transaction Logs with issues Demo 3 - Full backups and Transaction logs Demo 4 - Full, Differential, and Transactional Backups
12
T-SQL SCRIPTS Ability to have the maintenance plan execute custom code for your environment Could be used to send emails if not using the standard Database Mail Manipulate data in the system Send reports to users from a select statement
13
DEMO Demo 5 - Execute T-SQL Statements
14
INTEGRITY CHECKS Runs the DBCC CHECKDB {DatabaseName} WITH NO_INFOMSGS DBCC CHECKDB(N‘DatabaseName', NOINDEX) What is checks: * -Runs DBCC CHECKALLOC on the database.DBCC CHECKALLOC -Runs DBCC CHECKTABLE on every table and view in the database.DBCC CHECKTABLE -Runs DBCC CHECKCATALOG on the database.DBCC CHECKCATALOG
15
INTEGRITY CHECKS Validates the contents of every indexed view in the database. Validates link-level consistency between table metadata and file system directories and files when storing varbinary(max) data in the file system using FILESTREAM. Validates the Service Broker data in the database.
16
INTEGRITY CHECKS TempDB is used -Use WITH ESTIMATEONLY to get an understanding of how space is needed Performs parallel checking -To disable trace flag 2528
17
INTEGRITY CHECKS No Need to run DBCC CHECKALLOC,DBCC CHECKTABLE, DBCC CHECKCATALOG http://msdn.microsoft.com/en-us/library/ms176064.aspx New in SQL 2016 Maintenance plans (Older version needed T-SQL) -Physical only -Page, headers, allocation – No Filestream -Tablock -DBCC CHECKCATALOG Not run. Used Locks instead of a database snapshot.
18
INTEGRITY CHECKS More control over what is executed Best Practices “We recommend that you use the PHYSICAL_ONLY option for frequent use on production systems. Using PHYSICAL_ONLY can greatly shorten run-time for DBCC CHECKDB on large databases. We also recommend that you periodically run DBCC CHECKDB with no options. How frequently you should perform these runs depends on individual businesses and their production environments.” * http://msdn.microsoft.com/en-us/library/ms176064.aspxhttp://msdn.microsoft.com/en-us/library/ms176064.aspx
19
INTEGRITY CHECKS DBCC CHECKDB [ [ ( database_name | database_id | 0 [, NOINDEX |, { REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST | REPAIR_REBUILD } ] ) ] [ WITH { [ ALL_ERRORMSGS ] [, EXTENDED_LOGICAL_CHECKS ] [, NO_INFOMSGS ] [, TABLOCK ] [, ESTIMATEONLY ] [, { PHYSICAL_ONLY | DATA_PURITY } ] } ] ]
20
DEMO Demo 6 - Check Database Integrity Standard Demo 7 - Check Database Integrity Customized
21
INDEXES Two options Reorganize -All Databases, System, User, selected -If Selected – Table, View, Both -If Table or View Can select individual object
22
INDEXES Rebuild Options -All Databases, System, User, selected -Default Percent Free, set percent Free -If Selected – Table, View, Both -If Table or View Can select individual Object -Use Tempdb -Keep online -SQL 2016 -Abort after wait -Max Duration
23
INDEXES Best Practices When to reorganize verses when to rebuild Sys.dm_db_index_physical_stats() < = 5% - do nothing >5% and <=30% Reorganize > 30% Rebuild Rebuilding on or offline Reorganizing always online *http://technet.microsoft.com/en-us/library/ms189858.aspx
24
DEMO Demo 8 - Bad Index Maintenance Plan Demo 9 - Indexes Standard Task Demo 10 - Indexes Customized
25
UPDATE STATS What are statistics -Table, indexes When should you run Update Statistics DBCC SHOW_STATISTICS -Individual Stats Filtered Statistics AUTO_UPDATE_STATISTICS AUTO_UPDATE_STATISTICS_ASYNC
26
UPDATE STATS All Databases, System, User, selected If Selected – Table, View, Both If Table or View -Can select individual Object All existing Stats, Column, Index Full Scan or Sample
27
UPDATE STATS Sp_updatestats – will help when your use of the Update Stats task it taking to long. Only updates outdates stats looks at the rowmodctr in sys.indexes Compatibility level of 90 or higher, sp_updatestats does preserves the latest NORECOMPUTE
28
UPDATE STATS Index rebuilds and re-organization do not change the distribution of data -Index Rebuilds will update statistics for the index -2012 partition indexes do not update stats on create or rebuild
29
UPDATE STATS To see last updated date for index stats SELECT name AS index_name, STATS_DATE(object_id, index_id) AS statistics_update_date FROM sys.indexes where name not in ('nc3','clust','clst','cl','nc','nc2','nc1') order by statistics_Update_Date; GO
30
DEMO Demo 11 - Update Statistics
31
CLEAN UP TASKS Maintenance Backups Uses undocumented dbo.xp_delete_file EXECUTE master.dbo.xp_delete_file 0,N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup',N' bak',N'2012-12-21T10:49:22',1 Option master.sys.xp_delete_file if you want to manually run Maintenance Plan Reports History
32
DEMO Demo 12 - Cleanup Tasks Every Plan Demo 13 - Cleanup Tasks Individual Plan Demo 14 - Cleanup Best Plan
33
SHRINK DATABASE Ability to shrink your databases But should you?
34
SQL AGENT JOBS Flexibility to run items outside of the standard Maintenance plan items.
35
DEMO Demo 15 - SQL Agent Jobs Demo 16 - Putting things all together
36
TO USE OR NOT TO USE...
37
SUMMARY Routine tasks to help keep your database happy When you should use the provided tasks When you should create your own KISS or complex Always remember to clean up your history
38
REFERENCES http://msdn.microsoft.com/en-us/library/ms187658.aspx http://ola.hallengren.com/ http://www.bradmcgehee.com/2010/01/free-ebook-on- sql-server-maintenance-plans-now-available/http://www.bradmcgehee.com/2010/01/free-ebook-on- sql-server-maintenance-plans-now-available/
39
Q&A - THANK YOU! Kat Long kmeadows@xtivia.com @KatSQL www.xtivia.com SQL Server Maintenance Plans
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.