Each of experienced administrators used (to some extent) what is called Maintenance Plans - Plans of Conservation. During this session, I'd like to discuss what can be useful for us to provide functionality when we use them and what to look out for.
3. SELECT {BIO}
Polish SQL Server User Group Leader
Microsoft Certified Trainer
MCP, MCSA, MLSS, MLSBS, MCTS, MCITP, MCT
SQL Server MVP from 2010
Friends of RedGate PLUS
PASS SQL Azure Virtual Chapter Co-Founder
Blogger, Influencer, Technical Writer
Last 8 years (living) in Data Center in Wrocław
Generally about 14 years in IT/banking area
GITCA Technical Lead & Vice-Chair EMEA Board
Speaker at SQL Server Community Launch, Time for SharePoint, CodeCamps, SharePoint
Community Launch, CISSP Day, InfoTRAMS, SQLSaturday, SQLBits, CarreerCon, SQL Rally
Autor of few articles on TechNet (PL) and WSS.pl portal
Deep Dives Co-Author:
High availability of SQL Server in the context
of Service Level Agreements (Chapter 18th)
Technical reviewer:
Exploring MDX in SQL Server 2012
Working for Microsoft Subject Matter Expert and Terminology Community
(Windows 7, 8 & Visualstudio 2010,2012)
3
4. AGENDA
Maintenance Plans – what are you talking about?
Maintenance Plans – how, where, when?
• Methods, tools, right (?) ways
What Maintenance Plans can do you You
• Back Up Database
• Verify Integrity of Database
• Maintain a Database Indexes
• Maintain Index & Column Statistics
• Remove Older Data from msdb
• Remove Old Backups
Examples
Q&A
Budapest | November 27th, 2013
4
6. MAINTENANCE PLANS – WHAT ARE YOU TALKING ABOUT?
•
•
•
•
Clean Environment
Silence
Knowledge about environment
Productivity / Performance
DEFINITION:
A database maintenance plan is a set of specific, proactive task
that need to be performer regularly on databases to ensure
their adequate performance and availability
Budapest | November 27th, 2013
6
8. MAINTENANCE PLANS – HOW, WHERE, WHEN?
HOW:
• Maintenance Plan Wizard
• Maintenance Plan Designer
• T-SQL Scripts
• PowerShell Scripts
WHERE
• SQL Server Management Studio from Standard and above
• See you in… Express
WHEN:
• BEFORE: problems / service windows
• AFTER: maintaining / clients back to home
Budapest | November 27th, 2013
8
9. HOW: MAINTENANCE PLAN WIZARD
•
•
•
•
•
Very simple (although advanced) wizard
Providing possibility for creation simple task in dozens of seconds
Enough in many cases, environments
Limited but huge number of options
Limitations:
• number of databases
• granularity
• single tasks / no multitasking
• no scripting for another instances
• some known problems in previous version of SQL Server
o SQL Server 2005 Service Pack 2
o SQL Server 2008
Budapest | November 27th, 2013
9
10. HOW: MAINTENANCE PLAN DESIGNER
•
•
•
•
More flexible and advanced tool (not on this session)
Graphical user interface with SSIS
Most often used for „really DBA”
Increased features
• Workflow for specified tasks with execution plan
• Multitasking
• Two additional Maintenance plans
o Execute T-SQL Statement
o Notify Operator
Budapest | November 27th, 2013
10
11. LIMITATIONS: MAINTENANCE PLAN WIZARD & DESIGNER
• Limitations for both tools / those ideas are not possible
• Identification and removing fragmentation for physical files
• Identification abandoned, duplicated, forgotten indexes
• Providing backup on demand
• Werification good quality of backup
• Werification succesful restore
• Monitoring of performance
• Monitoring of SQL OS
• Monitoring of Windows OS
• Monitoring available space
Budapest | November 27th, 2013
11
12. MAINTENANCE PLAN: T-SQL & POWERSHELL SCRIPTS
• Functionality for „Real *Tru* DBA”
• Necessary for working with multiple databases, instances, server farms
• Feauters for scripting:
• Access to OS
• Posibility of moving
• Scripts sharing
One of the best examples and tools for free:
HTTP://OLA.HALLENGREN.COM/
Budapest | November 27th, 2013
12
14. MAINTENANCE PLANS: AVAILABLE TASKS
• Check Database Integrity
• DBCC CHECKDB
• Shrink Database
• NEVER, NEVER, NEVER
• Reorganize Index
• ALTER INDEX , and next Update Statistics
• Rebuild Index
• ALTER INDEX, Update Statistics are not necessary
• Update Statistics
• Sp_updatestats
• History Cleanup
• Using msdb, don’t do that too much frequently
• Execute SQL Server Agent Job
• Providing scrip using wen You work with agent
• Back Up Database (Full)
• Executing BACKUP DATABASE with FULL option, and next Transaction Log
• Back Up Database (Differential)
• Executing BACKUP DATABASE with DIFFERENTIAL option
• Back Up Database (Transaction Log)
• Executing BACKUP LOG, frequency...
• Maintenance Cleanup Task
• Most complicated feature ? BAK, TRN, TXT
Budapest | November 27th, 2013
14
15. FUNCTIONALITY: VERIFY INTEGRITY OF DATABASE
YOU SHOULD REMEMBER
• using DBCC CHECKDB
• Daily
• Weekly
• Monthly
• DBCC CHECKDB (’database_name’) WITH NO_INFOMSGS
• Suppresses all informational messages.
• DBCC CHECKDB (’database_name’) WITH NO_INFOMSGS, ALL_ERRORMSGS
• Displays all reported errors per object. All error messages are displayed by default. Specifying or
omitting this option has no effect. Error messages are sorted by object ID, except for those
messages generated from tempdb database.
• In SQL Server Management Studio, the maximum number of error messages returned is 1000.
• DBCC CHECKDB (’database_name’) NOINDEX
• Specifies that intensive checks of nonclustered indexes for user tables should not be performed.
This decreases the overall execution time. NOINDEX does not affect system tables because
integrity checks are always performed on system table indexes
Budapest | November 27th, 2013
15
16. POSSIBILITIES: SHRINK DATABASE
YOU SHOULD REMEMBER
NEVER USE THIS OPTION IN MAINTENACE PLANS
MDF & LDF
100 GB reserved
15 GB in use
DBCC SHRINKDATABASE
or
• DBCC SHRINKFILE | MANUAL MODE
•
•
•
•
Reduction of Reserved Space
Budapest | November 27th, 2013
16
17. POSSIBILITIES: MAINTAIN INDEX & COLUMN STATISTICS
YOU SHOULD REMEMBER
Automation:
• AUTO_CREATE_STATISTICS
• AUTO_UPDATE_STATISTICS
• Executing automatically after: INSERT, UPDATE, DELETE
• UPDATE STATISTICS table_name WITH FULLSCAN
When:
• Never…
• Just after Index Reorganization
• On the days when we’re not using Index Rebuild or Reorganize Index
Important options (UPDATE STATISTICS):
• All existing statistics
• Column statistics only
• Index statistics only
Budapest | November 27th, 2013
17
19. POSSIBILITIES: HISTORY CLEAN UP (MSDB)
Choosing the data (right data) for deleting:
• Backup and restore history
• SQL Server Agent job history
• Maintenance Plan history
Budapest | November 27th, 2013
19
21. • We should remember about:
• Task sequences
• Task execution
• Task priority
• Documentation
• Using: daily / weekly / occasionally
• Better expoloration of our environment
• Monitoring (partially) of performance
• Standard and above (sorry)
• Maintenance Plan Wizard
• for beginners and small installations
• Maintenance Plan Designer
• Adult , more complicated, wide environment
Budapest | November 27th, 2013
21
22. LINKS
• Brad McGehee | Brad’ Sure Guide to SQL Server Maintenance Plans
„My new eBook, Brad’ Sure Guide to SQL Server Maintenance Plans is now available as
a free, 269 page PDF eBook. The book is designed for part-time or novice DBAs who
want to learn how to properly create Maintenance Plans using the tools that come with
SQL Server Management Studio (SSMS) in SQL Server 2005/2008.
LINK: http://bit.ly/1ijdnah
• Ola Hallengreen | Maintenance Plans Scripts PASS slidedeck
„The SQL Server Maintenance Solution comprises scripts for running backups,
integrity checks, and index and statistics maintenance on all editions of Microsoft
SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012. The
solution is based on stored procedures, sqlcmd utility, and SQL Server Agent jobs”
LINK: http://bit.ly/1b220Ns
Budapest | November 27th, 2013
22