SlideShare a Scribd company logo
1 of 37
Brad M McGehee
Microsoft SQL Server MVP
Director of DBA Education
Red Gate Software
bradmcgehee@hotmail.com
 You may be a part-time or full-time DBA
 You may be a DBA Administrator or DBA Developer
 You may have less than one year’s experience as a
SQL Server DBA, and are still adding to your skill set
 You may be an experienced DBA:
 And, you know you are never too smart to learn something
new.
 Or, you don’t mind being reminded of something you may
have forgotten.
 What is Database Maintenance?
 Why is Database Maintenance Important?
 How Do Database Maintenance Plans Fit In?
 Key Database MaintenanceTasks
 Physical File Defragmentation
 Database and Log File Management
 tempdb Maintenance
 msdb Maintenance
 Index Maintenance
 Statistics Maintenance
 Data Corruption Detection
 Database and Log File Protection
 Database Maintenance Monitoring
 Database Maintenance Best Practices
 Database maintenance includes a defined set of
tasks that DBAs need to perform on a periodic
basis to ensure that their databases:
 Perform Optimally
 Maintain High Availability
 Another way to look at this is: if appropriate
database maintenance is not performed as
needed, then you can expect to see:
 Degraded performance
 Unexpected downtime
 While many of the maintenance tasks discussed today might
seem small, the accumulative effect of following each
recommendation can be huge.
 By following these best practices, SQL Server performance
and availability can be boosted by 10%, 20%, or even more.
Increased Performance and Availability
Number of
optimal
maintenance
tasks
implemented
 The Database Maintenance PlanWizard is not an ideal tool for
performing database maintenance.
 While it is designed with the “novice” DBA in mind, unfortunately:
 It is harder to use than it appears to be
 It is not very flexible and it is hard to modify after the fact
 It is hard to troubleshoot if there are problems
 It allows DBAs to create maintenance plans that can:
 Significantly hurt the performance of SQL Server
 Give a false sense of security in regard to availability
 Ideally, you should avoid using the Database Maintenance Wizard.
But if you can’t, be sure to research each of your options and select
the ones that best meet your needs.
 Physical File Fragmentation
 Database and Log File Management
 tempdb Maintenance
 msdb Maintenance
 Index Maintenance
 Statistics Maintenance
 Data Corruption Detection
 Database and Log File Protection
 Database Maintenance Monitoring
 This list is not designed to be all encompassing, but it does include key tasks that all
DBAs need to perform regularly.
 The assumption is that your hardware, OS, SQL Server, and application are optimally
configured.
 When the OS writes a file to disk, if contiguous
clusters are not available, they are written
elsewhere on the disk.
 When a file is stored in a non-contiguous
manner, then the file is considered to be
physically fragmented.
 Physical file fragmentation can contribute to an
additional load on your I/O subsystem and
reduce I/O performance.
 SQL Server does not know about file fragmentation,
but is affected indirectly by it because the OS has to
do more work to move data to and from SQL Server
to disk.
 The amount of file fragmentation’s negative affect
on SQL Server’s performance depends on many
different factors. For example, random reads are less
affected by fragmentation than sequential reads.
 Since we know fragmentation can affect SQL Server
I/O performance, our goal should be to minimize it
as much as possible, even though it might be hard to
quantify.
 SQL Server is designed to minimize physical file
fragmentation, assuming the DBA is smart about
the way he or she manages physical files.
 Ways to minimize physical file fragmentation:
 Ensure there is no physical file fragmentation before
creating new databases and log files.
 Pre-size MDF and LDF files instead of letting
autogrowth automatically size files.
 As needed, defragment physical files, either manually
or with scheduled job.
 In theory, MDF and LDF files “manage” themselves.
 In reality, for optimal performance, DBAs must take
full responsibility of managing them.This includes:
 Ensuring instant file initialization is turned on
 Locating MDF and LDF files appropriately
 Pre-sizing MDF and LDF files appropriately
 Setting appropriate autogrowth settings
 Taking care when shrinking MDF and LDF files
 Monitoring MDF and LDF file growth
 When instant file initialization is enabled, it prevents MDF (not
LDF) files from being zeroed out, speeding up their creation.
 Speeds up CREATE DATABASE,ALTER DATABASE, RESTORE
DATABASE, and autogrowth. Also speeds database recovery.
 Requires SQL Server 2005/2008, andWindows Server 2003/2008
 Instant file initialization is turned on if the SQL Server service
account has been granted the SE_MANAGE_VOLUME_NAME
permission. Members of the localWindows Administrator group
have this right and can grant it to other accounts by adding
them to the PerformVolume MaintenanceTasks security policy.
 The OS, pagefile.sys, and SQL Server binaries
should be located on their own disk volume.
 MDF files should be located on their own disk
volume.
 LDF files should be located on their own disk
volume.
 Benefits:
 Reduces I/O contention and offers better I/O
performance
 Reduces physical file fragmentation
 The DBA needs to estimate the future potential size of the MDF file,
and then create the MDF file to that size.
 The DBA needs to estimate the future potential size of the LDF file,
and then create the LDF file to that size. Harder to estimate. May
have to make educated guess, then resize later once you have data
to work with.
 As needed, MDF and LDF files should be modified manually.
 Benefits:
 Reduces physical file fragmentation
 Reduces unexpected autogrowth events
 For log files, prevents LDF file from becoming fragmented into excessive multiple
Virtual Log Files, which can hurt performance.
 Autogrowth should not be used to manage file
growth.
 Autogrowth should only be used to cover
unexpected file growth.
 Autogrowth, by default, is set to grow MDB by 1MB
at a time, and LDF is set to grow by 10% at a time.
 Set autogrowth to grow by a fixed amount you
choose, and not a percentage amount.
 Choose a fixed amount that won’t result in a lot of
autogrowth, but is not so large that it will create a
lot of space that won’t be used in the immediate
future.
 Don’t use Auto Shrink (database option).
 Don’t schedule database or file shrinking operations.
 If you must shrink a database:
 Do so manually
 Rebuild the indexes after the shrink is complete
 Schedule during slow time of the day
 Benefits of not automatically shrinking files:
 Eliminates grow and shrink syndrome
 Reduces physical file fragmentation
 Reduces resources used for these operations, allowing
more important tasks to use them
 If very active, locate on its own disk volume.
 Divide tempdb into multiple physical files, so that the number of
files is about 50% to 100% of the number of CPU cores your server
has.
 Each physical file should be the same size, and be set to the same
autogrowth amount.
 Pre-size tempdb to “typical size” so autogrowth doesn’t have to
happen. Default starting size is only 8MB.
 Set Autogrowth to avoid growth spurts, use fixed amount.
 Don’t shrink tempdb using DBCC SHRINKFILE, use ALTER
DATABASE and then restart server.
 Over time, the msdb database can grow large,
storing old data you probably don’t need, like:
 Backup and restore history (sp_delete_backuphistory)
 SQL Server Agent Job history (sp_purge_jobhistory)
 Maintenance Plan history (sp_maintplan_delete_log)
 You should periodically clear out the older data,
possibly shrink the database, and then rebuild all
of its indexes.
 Index Fragmentation Hurts Performance
 Over time, as indexes are subjected to data modifications,
gaps in data on pages develop, and the logical ordering of
the data no longer matches the physical ordering of the
data.This is a normal behaviour, but must be regularly
addressed.
 Heavily fragmented indexes can lead to poor query
performance, especially if scans occur regularly.
 Because of this, it is important that DBAs regularly detect
and remove index fragmentation from their databases on a
regular basis.
 There are three ways to remove fragmentation
from an index:
 Reorganize—online
 Rebuild—offline
 Rebuild—online (Enterprise Edition Only)
 This is an online task that doesn’t block user activity.
 Uses an in-place algorithm to reorganize indexes at leaf level.
 Removes much fragmentation and empty space, but not all.
 Only reduces fragmentation if necessary.
 Generally takes more time than Rebuild to complete.
 Can be stopped and started without losing work.
 Less resources are required to reorganize than Rebuild.
 Less disk space is required to reorganize than Rebuild.
 Generally, produces less logging when in full recovery mode.
 Index statistics are not updated (must perform this task
separately).
 Considered to be an off-line activity (unless you have EE).
 Index is rebuilt from scratch, and old index is dropped.
 Virtually all fragmentation and empty space is removed.
 Everything is rebuilt, whether it needs it or not.
 Rebuild is generally faster than using Reorganize.
 Index rebuild is atomic, can’t be stopped and restarted.
 More physical resources are required then Reorganize.
 Additional disk space is required than Reorganize.
 Will cause log file to grow, as operation is logged.
 Index statistics are updated with a FULLSCAN.
 Only Reorganize or Rebuild indexes that need it, don’t defrag
all indexes all the time.
 If fragmentation is less <5%, then leave alone.
 If fragmentation is >5% and <30%, consider Reorganize.
 If fragmentation >30%, consider Rebuild.
 Use sys.dm_db_index_physical_stats to help you determine
if an index should be rebuilt or not.
 Reorganize or Rebuild jobs should be scheduled as a SQL
Server Agent job using a customT-SQL script you create to
meet your environment’s specific needs.
 Indexing Needs Change OverTime
 Over time, data in databases, and the use of this data,
often changes.
 This means that the current indexing scheme may need to
be changed over time.
 For examples, indexes may need to be added, modified, or
removed for optimal query performance.
 The easiest way to do this is to run the Database Engine
Tuning Advisor against a ProfilerTrace on a periodic basis.
 The best way is to identify missing indexes is to use Profiler to
capture a trace file, and then use the Database EngineTuning
Advisor (DTA) to analyze the trace to look for recommendations.
 When capturing a ProfilerTrace, use the “Tuning” template and
capture data over a representative time frame.
 If your trace files become large, you may need to create multiple
traces over the course of a day to get a representative sample of
activity.
 Run the DTA against the trace data, review recommendations,
and then add appropriate indexes.
 Most databases have one or more indexes that were
created because they seemed that they might be
useful, but they have ended up not being used.
 Because indexes need to be maintained when data
changes in a table, maintaining indexes that are not
used is a waste of resources.
 Periodically, identify unused indexes and remove
them.
 Use the sys.dm_db_index_usage_stats DMV to help
you identify unused indexes.
 Keep in mind that the data in this DMV is cleared out
each time SQL Server is restarted.
 SQL Server maintains statistics on indexes (and
some non-indexed columns) which are used by
the query optimizer to help produce an optimal
query plan.
 If these statistics are out of date, or not
representative, then the query optimizer may
produce a poorly performing query plan.
 As DBAs, we need to ensure that appropriate
statistics are created and stay updated.
 Ensure that “Auto Create Statistics” and “Auto Update Statistics”
are set to “true” for all databases.
 If Rebuilding indexes, statistics are automatically updated with
FULLSCAN, so you don’t need to update statistics separately.
 If Reorganizing indexes, statistics are not automatically
updated, so you should update statistics manually afterwards.
 Use sp_updatestats to update statistics. This command runs
UPDATE STATISTICS only on those statistics that require
updating, helping to conserve server resources.
 There are two major causes of data corruption:
 Physical: Data has been altered in negative way, often
caused by hardware or hardware drivers.
 Logical:A data relationship has been broken
 There are two ways to help identify these types
of data corruption:
 Turn on the “checksum” for your databases.
 Run DBCC CHECKDB as often as you make full
backups.
 This database setting calculates a checksum over
the contents of a page and stores the value in the
page header when the page is written to disk.
 When the page is read from disk, the checksum is
recomputed and compared to the checksum value
stored in the page header.
 If the values do not match, error message 824 is
reported to both the SQL Server error log and the
Windows event log.
 When you see this error, you need to take action
now.
 Offers better protection than torn page detection.
 DBCC CHECKDB checks the logical and physical integrity of all objects in
a database.
 Ideally, the command should be run before a full database backup is made
to identify problems before the backup occurs.
 If a problem is detected, you want to identify, and correct it, as soon as
possible.
 DBCC CHECKDB has some very limited “fixing” ability, but it should not
be counted upon, and only used by experts.
 Running DBCC CHECKDB is resource-intensive and should be run during
slow times on the server.
 If you don’t have a large enough window to run CHECKDB, restore
database to another server and run CHECKDB there.
 Production databases should use the Full Recovery model.
 Create a job to perform full backups daily on all system and user
production databases, plus log backups hourly (or similar).
 Always backup using RESTORE WITHVERIFYONLY to help verify
backup integrity.
 Randomly restore backups to verify that you can restore your
databases.
 Create, and enforce, an appropriate data retention policy.
 Store backups securely and off-site.
 If you have a limited backup window, or have limited disk space,
use backup compression. Can be a big time saver.
 Monitor MDF and LDF file growth
 Monitor Free Space—Should have 15% or more free
space
 Monitor SQL Server and OS Logs
 Monitor Jobs
 Monitor Alerts
 Monitor Performance
 Key Point: Even though it is a boring task, you need
to regularly monitor your SQL Server instances.
 Manual checks
 SQL Server Alerts
 OS Event Log Alerts
 Performance Monitor Alerts
 Profiler
 SQL Server Standard Reports
 Performance Data Collector (2008)
 Write your own monitoring system
 Use a third-party tool
 Create maintenance tasks yourself, don’t depend on the
Database Maintenance Wizard.
 As much as practical, keep maintenance plans the same from
SQL Server instance to instance.
 Script jobs and reuse them when you can.
 Don’t over-maintain your databases. Find the right balance.
 Schedule database maintenance tasks during “down times” or
during the least busy time of the day.
 Don’t repeat the same maintenance tasks (e.g. Rebuild indexes,
then Update Statistics immediately thereafter).
 Schedule jobs so that they do not overlap one another.
 Implementing optimal maintenance plans can
greatly affect a SQL Server instances’:
 Availability
 Performance
 You need a good understanding of SQL Server
internals in order to properly maintain your
databases.
 Evaluate all of your SQL Server instances to ensure
that all appropriate maintenance tasks are being
performed, and are being performed optimally.
 Database maintenance is an on-going task that
never ends. Automate as much as possible.
 Free E-Books:
 www.sqlservercentral.com/Books
 Check these out:
 www.SQLServerCentral.com
 www.Simple-Talk.com
 www.SQL-Server-Performance.Com
 Contact me at:
bradmcgehee@hotmail.com
 Blogs:
www.simple-talk.com/community/blogs/brad_mcgehee/default.aspx
http://www.sqlservercentral.com/blogs/aloha_dba/default.aspx
http://twitter.com/bradmcgehee

More Related Content

What's hot

DBM 380 EDU Inspiring Innovation--dbm380edu.com
DBM 380 EDU Inspiring Innovation--dbm380edu.com DBM 380 EDU Inspiring Innovation--dbm380edu.com
DBM 380 EDU Inspiring Innovation--dbm380edu.com KeatonJennings99
 
DBM 380 AID Introduction Education--dbm380aid.com
DBM 380 AID Introduction Education--dbm380aid.comDBM 380 AID Introduction Education--dbm380aid.com
DBM 380 AID Introduction Education--dbm380aid.comkopiko205
 
DBM 380 HELP Inspiring Innovation--dbm380help.com
DBM 380 HELP Inspiring Innovation--dbm380help.comDBM 380 HELP Inspiring Innovation--dbm380help.com
DBM 380 HELP Inspiring Innovation--dbm380help.comsachin10204
 
DBM 380 HELP Education Planning--dbm380help.com
DBM 380 HELP Education Planning--dbm380help.comDBM 380 HELP Education Planning--dbm380help.com
DBM 380 HELP Education Planning--dbm380help.comcampfort12
 
DBM 380 HELP Achievement Education--dbm380help.com
DBM 380 HELP Achievement Education--dbm380help.comDBM 380 HELP Achievement Education--dbm380help.com
DBM 380 HELP Achievement Education--dbm380help.comkopiko147
 
DBM 380 EDU Redefined Education--dbm380edu.com
DBM 380 EDU Redefined Education--dbm380edu.comDBM 380 EDU Redefined Education--dbm380edu.com
DBM 380 EDU Redefined Education--dbm380edu.comkopiko173
 
DBM 380 AID Achievement Education--dbm380aid.com
DBM 380 AID Achievement Education--dbm380aid.comDBM 380 AID Achievement Education--dbm380aid.com
DBM 380 AID Achievement Education--dbm380aid.comagathachristie183
 
DBM 380 AID Inspiring Innovation--dbm380aid.com
DBM 380 AID Inspiring Innovation--dbm380aid.comDBM 380 AID Inspiring Innovation--dbm380aid.com
DBM 380 AID Inspiring Innovation--dbm380aid.comwilliamwordsworth50
 
DBM 380 HELP Become Exceptional--dbm380help.com
DBM 380 HELP Become Exceptional--dbm380help.comDBM 380 HELP Become Exceptional--dbm380help.com
DBM 380 HELP Become Exceptional--dbm380help.comagathachristie113
 
DBM 380 HELP Introduction Education--dbm380help.com
DBM 380 HELP Introduction Education--dbm380help.comDBM 380 HELP Introduction Education--dbm380help.com
DBM 380 HELP Introduction Education--dbm380help.comagathachristie266
 
DBM 380 AID Education for Service--dbm380aid.com
DBM 380 AID Education for Service--dbm380aid.comDBM 380 AID Education for Service--dbm380aid.com
DBM 380 AID Education for Service--dbm380aid.comkopiko64
 
DBM 380 Invent Yourself/newtonhelp.com
DBM 380 Invent Yourself/newtonhelp.comDBM 380 Invent Yourself/newtonhelp.com
DBM 380 Invent Yourself/newtonhelp.comlechenau119
 
The virtues of backup disaster recovery
The virtues of backup disaster recoveryThe virtues of backup disaster recovery
The virtues of backup disaster recoveryZack Fabro
 
Not having a good backup
Not having a good backupNot having a good backup
Not having a good backupRita Crawford
 
DBM 380 EDU Knowledge is divine-dbm380edu.com
DBM 380 EDU Knowledge is divine-dbm380edu.com DBM 380 EDU Knowledge is divine-dbm380edu.com
DBM 380 EDU Knowledge is divine-dbm380edu.com VSNaipaul1
 
DBM 380 EDU Education Planning--dbm380edu.com
DBM 380 EDU Education Planning--dbm380edu.comDBM 380 EDU Education Planning--dbm380edu.com
DBM 380 EDU Education Planning--dbm380edu.comWindyMiller8
 
DBM 380 HELP Knowledge is divine-dbm380help.com
DBM 380 HELP Knowledge is divine-dbm380help.comDBM 380 HELP Knowledge is divine-dbm380help.com
DBM 380 HELP Knowledge is divine-dbm380help.comVSNaipaul1
 
The High Performance DBA Optimizing Databases For High Performance
The High Performance DBA Optimizing Databases For High PerformanceThe High Performance DBA Optimizing Databases For High Performance
The High Performance DBA Optimizing Databases For High PerformanceEmbarcadero Technologies
 

What's hot (18)

DBM 380 EDU Inspiring Innovation--dbm380edu.com
DBM 380 EDU Inspiring Innovation--dbm380edu.com DBM 380 EDU Inspiring Innovation--dbm380edu.com
DBM 380 EDU Inspiring Innovation--dbm380edu.com
 
DBM 380 AID Introduction Education--dbm380aid.com
DBM 380 AID Introduction Education--dbm380aid.comDBM 380 AID Introduction Education--dbm380aid.com
DBM 380 AID Introduction Education--dbm380aid.com
 
DBM 380 HELP Inspiring Innovation--dbm380help.com
DBM 380 HELP Inspiring Innovation--dbm380help.comDBM 380 HELP Inspiring Innovation--dbm380help.com
DBM 380 HELP Inspiring Innovation--dbm380help.com
 
DBM 380 HELP Education Planning--dbm380help.com
DBM 380 HELP Education Planning--dbm380help.comDBM 380 HELP Education Planning--dbm380help.com
DBM 380 HELP Education Planning--dbm380help.com
 
DBM 380 HELP Achievement Education--dbm380help.com
DBM 380 HELP Achievement Education--dbm380help.comDBM 380 HELP Achievement Education--dbm380help.com
DBM 380 HELP Achievement Education--dbm380help.com
 
DBM 380 EDU Redefined Education--dbm380edu.com
DBM 380 EDU Redefined Education--dbm380edu.comDBM 380 EDU Redefined Education--dbm380edu.com
DBM 380 EDU Redefined Education--dbm380edu.com
 
DBM 380 AID Achievement Education--dbm380aid.com
DBM 380 AID Achievement Education--dbm380aid.comDBM 380 AID Achievement Education--dbm380aid.com
DBM 380 AID Achievement Education--dbm380aid.com
 
DBM 380 AID Inspiring Innovation--dbm380aid.com
DBM 380 AID Inspiring Innovation--dbm380aid.comDBM 380 AID Inspiring Innovation--dbm380aid.com
DBM 380 AID Inspiring Innovation--dbm380aid.com
 
DBM 380 HELP Become Exceptional--dbm380help.com
DBM 380 HELP Become Exceptional--dbm380help.comDBM 380 HELP Become Exceptional--dbm380help.com
DBM 380 HELP Become Exceptional--dbm380help.com
 
DBM 380 HELP Introduction Education--dbm380help.com
DBM 380 HELP Introduction Education--dbm380help.comDBM 380 HELP Introduction Education--dbm380help.com
DBM 380 HELP Introduction Education--dbm380help.com
 
DBM 380 AID Education for Service--dbm380aid.com
DBM 380 AID Education for Service--dbm380aid.comDBM 380 AID Education for Service--dbm380aid.com
DBM 380 AID Education for Service--dbm380aid.com
 
DBM 380 Invent Yourself/newtonhelp.com
DBM 380 Invent Yourself/newtonhelp.comDBM 380 Invent Yourself/newtonhelp.com
DBM 380 Invent Yourself/newtonhelp.com
 
The virtues of backup disaster recovery
The virtues of backup disaster recoveryThe virtues of backup disaster recovery
The virtues of backup disaster recovery
 
Not having a good backup
Not having a good backupNot having a good backup
Not having a good backup
 
DBM 380 EDU Knowledge is divine-dbm380edu.com
DBM 380 EDU Knowledge is divine-dbm380edu.com DBM 380 EDU Knowledge is divine-dbm380edu.com
DBM 380 EDU Knowledge is divine-dbm380edu.com
 
DBM 380 EDU Education Planning--dbm380edu.com
DBM 380 EDU Education Planning--dbm380edu.comDBM 380 EDU Education Planning--dbm380edu.com
DBM 380 EDU Education Planning--dbm380edu.com
 
DBM 380 HELP Knowledge is divine-dbm380help.com
DBM 380 HELP Knowledge is divine-dbm380help.comDBM 380 HELP Knowledge is divine-dbm380help.com
DBM 380 HELP Knowledge is divine-dbm380help.com
 
The High Performance DBA Optimizing Databases For High Performance
The High Performance DBA Optimizing Databases For High PerformanceThe High Performance DBA Optimizing Databases For High Performance
The High Performance DBA Optimizing Databases For High Performance
 

Viewers also liked

Maintenance and Management Best Practices from Support
Maintenance and Management Best Practices from SupportMaintenance and Management Best Practices from Support
Maintenance and Management Best Practices from SupportCA | Automic Software
 
ML Workshop 1: A New Architecture for Machine Learning Logistics
ML Workshop 1: A New Architecture for Machine Learning LogisticsML Workshop 1: A New Architecture for Machine Learning Logistics
ML Workshop 1: A New Architecture for Machine Learning LogisticsMapR Technologies
 
predictive maintenance
predictive maintenancepredictive maintenance
predictive maintenanceAmey Kulkarni
 
Building a performing Machine Learning model from A to Z
Building a performing Machine Learning model from A to ZBuilding a performing Machine Learning model from A to Z
Building a performing Machine Learning model from A to ZCharles Vestur
 
Big Data Meetup: Data Science & Big Data in Telecom
Big Data Meetup: Data Science & Big Data in TelecomBig Data Meetup: Data Science & Big Data in Telecom
Big Data Meetup: Data Science & Big Data in TelecomProvectus
 

Viewers also liked (7)

Maintenance and Management Best Practices from Support
Maintenance and Management Best Practices from SupportMaintenance and Management Best Practices from Support
Maintenance and Management Best Practices from Support
 
Using hadoop for big data
Using hadoop for big dataUsing hadoop for big data
Using hadoop for big data
 
ML Workshop 1: A New Architecture for Machine Learning Logistics
ML Workshop 1: A New Architecture for Machine Learning LogisticsML Workshop 1: A New Architecture for Machine Learning Logistics
ML Workshop 1: A New Architecture for Machine Learning Logistics
 
Myths of Data Science
Myths of Data ScienceMyths of Data Science
Myths of Data Science
 
predictive maintenance
predictive maintenancepredictive maintenance
predictive maintenance
 
Building a performing Machine Learning model from A to Z
Building a performing Machine Learning model from A to ZBuilding a performing Machine Learning model from A to Z
Building a performing Machine Learning model from A to Z
 
Big Data Meetup: Data Science & Big Data in Telecom
Big Data Meetup: Data Science & Big Data in TelecomBig Data Meetup: Data Science & Big Data in Telecom
Big Data Meetup: Data Science & Big Data in Telecom
 

Similar to SQL Server DBA Database Maintenance Best Practices

Pass chapter meeting - november - partitioning for database availability - ch...
Pass chapter meeting - november - partitioning for database availability - ch...Pass chapter meeting - november - partitioning for database availability - ch...
Pass chapter meeting - november - partitioning for database availability - ch...Charley Hanania
 
Sql server troubleshooting
Sql server troubleshootingSql server troubleshooting
Sql server troubleshootingNathan Winters
 
Large Scale SQL Considerations for SharePoint Deployments
Large Scale SQL Considerations for SharePoint DeploymentsLarge Scale SQL Considerations for SharePoint Deployments
Large Scale SQL Considerations for SharePoint DeploymentsJoel Oleson
 
Database Configuration for Maximum SharePoint 2010 Performance
Database Configuration for Maximum SharePoint 2010 PerformanceDatabase Configuration for Maximum SharePoint 2010 Performance
Database Configuration for Maximum SharePoint 2010 PerformanceEdwin M Sarmiento
 
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docxDBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docxseifusisay06
 
New Microsoft Office WordDatabase administration and automation Document (2)
New Microsoft Office WordDatabase administration and automation Document (2)New Microsoft Office WordDatabase administration and automation Document (2)
New Microsoft Office WordDatabase administration and automation Document (2)naveen
 
Introduction to Database Log Analysis
Introduction to Database Log AnalysisIntroduction to Database Log Analysis
Introduction to Database Log AnalysisAnton Chuvakin
 
12 cool features in defrag 12
12 cool features in defrag 1212 cool features in defrag 12
12 cool features in defrag 12aosborne
 
Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Ivan Sanders
 
SharePoint Intelligence Real World Business Workflow With Share Point Designe...
SharePoint Intelligence Real World Business Workflow With Share Point Designe...SharePoint Intelligence Real World Business Workflow With Share Point Designe...
SharePoint Intelligence Real World Business Workflow With Share Point Designe...Ivan Sanders
 
Sql Server tips from the field
Sql Server tips from the fieldSql Server tips from the field
Sql Server tips from the fieldInnoTech
 
SharePoint 2010 database maintenance
SharePoint 2010 database maintenanceSharePoint 2010 database maintenance
SharePoint 2010 database maintenanceMatt Ranlett
 
Database Design and Implementation
Database Design and ImplementationDatabase Design and Implementation
Database Design and ImplementationChristian Reina
 
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Knut Relbe-Moe [MVP, MCT]
 
Chapter 5 data processing
Chapter 5 data processingChapter 5 data processing
Chapter 5 data processingUMaine
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recoverysdrhr
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Jess Coburn
 

Similar to SQL Server DBA Database Maintenance Best Practices (20)

Dba101
Dba101Dba101
Dba101
 
Pass chapter meeting - november - partitioning for database availability - ch...
Pass chapter meeting - november - partitioning for database availability - ch...Pass chapter meeting - november - partitioning for database availability - ch...
Pass chapter meeting - november - partitioning for database availability - ch...
 
Sql server troubleshooting
Sql server troubleshootingSql server troubleshooting
Sql server troubleshooting
 
Large Scale SQL Considerations for SharePoint Deployments
Large Scale SQL Considerations for SharePoint DeploymentsLarge Scale SQL Considerations for SharePoint Deployments
Large Scale SQL Considerations for SharePoint Deployments
 
Database Configuration for Maximum SharePoint 2010 Performance
Database Configuration for Maximum SharePoint 2010 PerformanceDatabase Configuration for Maximum SharePoint 2010 Performance
Database Configuration for Maximum SharePoint 2010 Performance
 
Optimize TempDB
Optimize TempDB Optimize TempDB
Optimize TempDB
 
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docxDBA, LEVEL III TTLM Monitoring and Administering Database.docx
DBA, LEVEL III TTLM Monitoring and Administering Database.docx
 
New Microsoft Office WordDatabase administration and automation Document (2)
New Microsoft Office WordDatabase administration and automation Document (2)New Microsoft Office WordDatabase administration and automation Document (2)
New Microsoft Office WordDatabase administration and automation Document (2)
 
Introduction to Database Log Analysis
Introduction to Database Log AnalysisIntroduction to Database Log Analysis
Introduction to Database Log Analysis
 
12 cool features in defrag 12
12 cool features in defrag 1212 cool features in defrag 12
12 cool features in defrag 12
 
SharePoint Performance
SharePoint PerformanceSharePoint Performance
SharePoint Performance
 
Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013
 
SharePoint Intelligence Real World Business Workflow With Share Point Designe...
SharePoint Intelligence Real World Business Workflow With Share Point Designe...SharePoint Intelligence Real World Business Workflow With Share Point Designe...
SharePoint Intelligence Real World Business Workflow With Share Point Designe...
 
Sql Server tips from the field
Sql Server tips from the fieldSql Server tips from the field
Sql Server tips from the field
 
SharePoint 2010 database maintenance
SharePoint 2010 database maintenanceSharePoint 2010 database maintenance
SharePoint 2010 database maintenance
 
Database Design and Implementation
Database Design and ImplementationDatabase Design and Implementation
Database Design and Implementation
 
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
 
Chapter 5 data processing
Chapter 5 data processingChapter 5 data processing
Chapter 5 data processing
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11Orlando DNN Usergroup Pres 12/06/11
Orlando DNN Usergroup Pres 12/06/11
 

Recently uploaded

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

SQL Server DBA Database Maintenance Best Practices

  • 1. Brad M McGehee Microsoft SQL Server MVP Director of DBA Education Red Gate Software bradmcgehee@hotmail.com
  • 2.  You may be a part-time or full-time DBA  You may be a DBA Administrator or DBA Developer  You may have less than one year’s experience as a SQL Server DBA, and are still adding to your skill set  You may be an experienced DBA:  And, you know you are never too smart to learn something new.  Or, you don’t mind being reminded of something you may have forgotten.
  • 3.  What is Database Maintenance?  Why is Database Maintenance Important?  How Do Database Maintenance Plans Fit In?  Key Database MaintenanceTasks  Physical File Defragmentation  Database and Log File Management  tempdb Maintenance  msdb Maintenance  Index Maintenance  Statistics Maintenance  Data Corruption Detection  Database and Log File Protection  Database Maintenance Monitoring  Database Maintenance Best Practices
  • 4.  Database maintenance includes a defined set of tasks that DBAs need to perform on a periodic basis to ensure that their databases:  Perform Optimally  Maintain High Availability  Another way to look at this is: if appropriate database maintenance is not performed as needed, then you can expect to see:  Degraded performance  Unexpected downtime
  • 5.  While many of the maintenance tasks discussed today might seem small, the accumulative effect of following each recommendation can be huge.  By following these best practices, SQL Server performance and availability can be boosted by 10%, 20%, or even more. Increased Performance and Availability Number of optimal maintenance tasks implemented
  • 6.  The Database Maintenance PlanWizard is not an ideal tool for performing database maintenance.  While it is designed with the “novice” DBA in mind, unfortunately:  It is harder to use than it appears to be  It is not very flexible and it is hard to modify after the fact  It is hard to troubleshoot if there are problems  It allows DBAs to create maintenance plans that can:  Significantly hurt the performance of SQL Server  Give a false sense of security in regard to availability  Ideally, you should avoid using the Database Maintenance Wizard. But if you can’t, be sure to research each of your options and select the ones that best meet your needs.
  • 7.  Physical File Fragmentation  Database and Log File Management  tempdb Maintenance  msdb Maintenance  Index Maintenance  Statistics Maintenance  Data Corruption Detection  Database and Log File Protection  Database Maintenance Monitoring  This list is not designed to be all encompassing, but it does include key tasks that all DBAs need to perform regularly.  The assumption is that your hardware, OS, SQL Server, and application are optimally configured.
  • 8.  When the OS writes a file to disk, if contiguous clusters are not available, they are written elsewhere on the disk.  When a file is stored in a non-contiguous manner, then the file is considered to be physically fragmented.  Physical file fragmentation can contribute to an additional load on your I/O subsystem and reduce I/O performance.
  • 9.  SQL Server does not know about file fragmentation, but is affected indirectly by it because the OS has to do more work to move data to and from SQL Server to disk.  The amount of file fragmentation’s negative affect on SQL Server’s performance depends on many different factors. For example, random reads are less affected by fragmentation than sequential reads.  Since we know fragmentation can affect SQL Server I/O performance, our goal should be to minimize it as much as possible, even though it might be hard to quantify.
  • 10.  SQL Server is designed to minimize physical file fragmentation, assuming the DBA is smart about the way he or she manages physical files.  Ways to minimize physical file fragmentation:  Ensure there is no physical file fragmentation before creating new databases and log files.  Pre-size MDF and LDF files instead of letting autogrowth automatically size files.  As needed, defragment physical files, either manually or with scheduled job.
  • 11.  In theory, MDF and LDF files “manage” themselves.  In reality, for optimal performance, DBAs must take full responsibility of managing them.This includes:  Ensuring instant file initialization is turned on  Locating MDF and LDF files appropriately  Pre-sizing MDF and LDF files appropriately  Setting appropriate autogrowth settings  Taking care when shrinking MDF and LDF files  Monitoring MDF and LDF file growth
  • 12.  When instant file initialization is enabled, it prevents MDF (not LDF) files from being zeroed out, speeding up their creation.  Speeds up CREATE DATABASE,ALTER DATABASE, RESTORE DATABASE, and autogrowth. Also speeds database recovery.  Requires SQL Server 2005/2008, andWindows Server 2003/2008  Instant file initialization is turned on if the SQL Server service account has been granted the SE_MANAGE_VOLUME_NAME permission. Members of the localWindows Administrator group have this right and can grant it to other accounts by adding them to the PerformVolume MaintenanceTasks security policy.
  • 13.  The OS, pagefile.sys, and SQL Server binaries should be located on their own disk volume.  MDF files should be located on their own disk volume.  LDF files should be located on their own disk volume.  Benefits:  Reduces I/O contention and offers better I/O performance  Reduces physical file fragmentation
  • 14.  The DBA needs to estimate the future potential size of the MDF file, and then create the MDF file to that size.  The DBA needs to estimate the future potential size of the LDF file, and then create the LDF file to that size. Harder to estimate. May have to make educated guess, then resize later once you have data to work with.  As needed, MDF and LDF files should be modified manually.  Benefits:  Reduces physical file fragmentation  Reduces unexpected autogrowth events  For log files, prevents LDF file from becoming fragmented into excessive multiple Virtual Log Files, which can hurt performance.
  • 15.  Autogrowth should not be used to manage file growth.  Autogrowth should only be used to cover unexpected file growth.  Autogrowth, by default, is set to grow MDB by 1MB at a time, and LDF is set to grow by 10% at a time.  Set autogrowth to grow by a fixed amount you choose, and not a percentage amount.  Choose a fixed amount that won’t result in a lot of autogrowth, but is not so large that it will create a lot of space that won’t be used in the immediate future.
  • 16.  Don’t use Auto Shrink (database option).  Don’t schedule database or file shrinking operations.  If you must shrink a database:  Do so manually  Rebuild the indexes after the shrink is complete  Schedule during slow time of the day  Benefits of not automatically shrinking files:  Eliminates grow and shrink syndrome  Reduces physical file fragmentation  Reduces resources used for these operations, allowing more important tasks to use them
  • 17.  If very active, locate on its own disk volume.  Divide tempdb into multiple physical files, so that the number of files is about 50% to 100% of the number of CPU cores your server has.  Each physical file should be the same size, and be set to the same autogrowth amount.  Pre-size tempdb to “typical size” so autogrowth doesn’t have to happen. Default starting size is only 8MB.  Set Autogrowth to avoid growth spurts, use fixed amount.  Don’t shrink tempdb using DBCC SHRINKFILE, use ALTER DATABASE and then restart server.
  • 18.  Over time, the msdb database can grow large, storing old data you probably don’t need, like:  Backup and restore history (sp_delete_backuphistory)  SQL Server Agent Job history (sp_purge_jobhistory)  Maintenance Plan history (sp_maintplan_delete_log)  You should periodically clear out the older data, possibly shrink the database, and then rebuild all of its indexes.
  • 19.  Index Fragmentation Hurts Performance  Over time, as indexes are subjected to data modifications, gaps in data on pages develop, and the logical ordering of the data no longer matches the physical ordering of the data.This is a normal behaviour, but must be regularly addressed.  Heavily fragmented indexes can lead to poor query performance, especially if scans occur regularly.  Because of this, it is important that DBAs regularly detect and remove index fragmentation from their databases on a regular basis.
  • 20.  There are three ways to remove fragmentation from an index:  Reorganize—online  Rebuild—offline  Rebuild—online (Enterprise Edition Only)
  • 21.  This is an online task that doesn’t block user activity.  Uses an in-place algorithm to reorganize indexes at leaf level.  Removes much fragmentation and empty space, but not all.  Only reduces fragmentation if necessary.  Generally takes more time than Rebuild to complete.  Can be stopped and started without losing work.  Less resources are required to reorganize than Rebuild.  Less disk space is required to reorganize than Rebuild.  Generally, produces less logging when in full recovery mode.  Index statistics are not updated (must perform this task separately).
  • 22.  Considered to be an off-line activity (unless you have EE).  Index is rebuilt from scratch, and old index is dropped.  Virtually all fragmentation and empty space is removed.  Everything is rebuilt, whether it needs it or not.  Rebuild is generally faster than using Reorganize.  Index rebuild is atomic, can’t be stopped and restarted.  More physical resources are required then Reorganize.  Additional disk space is required than Reorganize.  Will cause log file to grow, as operation is logged.  Index statistics are updated with a FULLSCAN.
  • 23.  Only Reorganize or Rebuild indexes that need it, don’t defrag all indexes all the time.  If fragmentation is less <5%, then leave alone.  If fragmentation is >5% and <30%, consider Reorganize.  If fragmentation >30%, consider Rebuild.  Use sys.dm_db_index_physical_stats to help you determine if an index should be rebuilt or not.  Reorganize or Rebuild jobs should be scheduled as a SQL Server Agent job using a customT-SQL script you create to meet your environment’s specific needs.
  • 24.  Indexing Needs Change OverTime  Over time, data in databases, and the use of this data, often changes.  This means that the current indexing scheme may need to be changed over time.  For examples, indexes may need to be added, modified, or removed for optimal query performance.  The easiest way to do this is to run the Database Engine Tuning Advisor against a ProfilerTrace on a periodic basis.
  • 25.  The best way is to identify missing indexes is to use Profiler to capture a trace file, and then use the Database EngineTuning Advisor (DTA) to analyze the trace to look for recommendations.  When capturing a ProfilerTrace, use the “Tuning” template and capture data over a representative time frame.  If your trace files become large, you may need to create multiple traces over the course of a day to get a representative sample of activity.  Run the DTA against the trace data, review recommendations, and then add appropriate indexes.
  • 26.  Most databases have one or more indexes that were created because they seemed that they might be useful, but they have ended up not being used.  Because indexes need to be maintained when data changes in a table, maintaining indexes that are not used is a waste of resources.  Periodically, identify unused indexes and remove them.  Use the sys.dm_db_index_usage_stats DMV to help you identify unused indexes.  Keep in mind that the data in this DMV is cleared out each time SQL Server is restarted.
  • 27.  SQL Server maintains statistics on indexes (and some non-indexed columns) which are used by the query optimizer to help produce an optimal query plan.  If these statistics are out of date, or not representative, then the query optimizer may produce a poorly performing query plan.  As DBAs, we need to ensure that appropriate statistics are created and stay updated.
  • 28.  Ensure that “Auto Create Statistics” and “Auto Update Statistics” are set to “true” for all databases.  If Rebuilding indexes, statistics are automatically updated with FULLSCAN, so you don’t need to update statistics separately.  If Reorganizing indexes, statistics are not automatically updated, so you should update statistics manually afterwards.  Use sp_updatestats to update statistics. This command runs UPDATE STATISTICS only on those statistics that require updating, helping to conserve server resources.
  • 29.  There are two major causes of data corruption:  Physical: Data has been altered in negative way, often caused by hardware or hardware drivers.  Logical:A data relationship has been broken  There are two ways to help identify these types of data corruption:  Turn on the “checksum” for your databases.  Run DBCC CHECKDB as often as you make full backups.
  • 30.  This database setting calculates a checksum over the contents of a page and stores the value in the page header when the page is written to disk.  When the page is read from disk, the checksum is recomputed and compared to the checksum value stored in the page header.  If the values do not match, error message 824 is reported to both the SQL Server error log and the Windows event log.  When you see this error, you need to take action now.  Offers better protection than torn page detection.
  • 31.  DBCC CHECKDB checks the logical and physical integrity of all objects in a database.  Ideally, the command should be run before a full database backup is made to identify problems before the backup occurs.  If a problem is detected, you want to identify, and correct it, as soon as possible.  DBCC CHECKDB has some very limited “fixing” ability, but it should not be counted upon, and only used by experts.  Running DBCC CHECKDB is resource-intensive and should be run during slow times on the server.  If you don’t have a large enough window to run CHECKDB, restore database to another server and run CHECKDB there.
  • 32.  Production databases should use the Full Recovery model.  Create a job to perform full backups daily on all system and user production databases, plus log backups hourly (or similar).  Always backup using RESTORE WITHVERIFYONLY to help verify backup integrity.  Randomly restore backups to verify that you can restore your databases.  Create, and enforce, an appropriate data retention policy.  Store backups securely and off-site.  If you have a limited backup window, or have limited disk space, use backup compression. Can be a big time saver.
  • 33.  Monitor MDF and LDF file growth  Monitor Free Space—Should have 15% or more free space  Monitor SQL Server and OS Logs  Monitor Jobs  Monitor Alerts  Monitor Performance  Key Point: Even though it is a boring task, you need to regularly monitor your SQL Server instances.
  • 34.  Manual checks  SQL Server Alerts  OS Event Log Alerts  Performance Monitor Alerts  Profiler  SQL Server Standard Reports  Performance Data Collector (2008)  Write your own monitoring system  Use a third-party tool
  • 35.  Create maintenance tasks yourself, don’t depend on the Database Maintenance Wizard.  As much as practical, keep maintenance plans the same from SQL Server instance to instance.  Script jobs and reuse them when you can.  Don’t over-maintain your databases. Find the right balance.  Schedule database maintenance tasks during “down times” or during the least busy time of the day.  Don’t repeat the same maintenance tasks (e.g. Rebuild indexes, then Update Statistics immediately thereafter).  Schedule jobs so that they do not overlap one another.
  • 36.  Implementing optimal maintenance plans can greatly affect a SQL Server instances’:  Availability  Performance  You need a good understanding of SQL Server internals in order to properly maintain your databases.  Evaluate all of your SQL Server instances to ensure that all appropriate maintenance tasks are being performed, and are being performed optimally.  Database maintenance is an on-going task that never ends. Automate as much as possible.
  • 37.  Free E-Books:  www.sqlservercentral.com/Books  Check these out:  www.SQLServerCentral.com  www.Simple-Talk.com  www.SQL-Server-Performance.Com  Contact me at: bradmcgehee@hotmail.com  Blogs: www.simple-talk.com/community/blogs/brad_mcgehee/default.aspx http://www.sqlservercentral.com/blogs/aloha_dba/default.aspx http://twitter.com/bradmcgehee

Editor's Notes

  1. Use auto maintenance analogy.
  2. Quick Demo of main screen that shows tasks.
  3. http://blogs.technet.com/askperf/archive/2008/03/14/disk-fragmentation-and-system-performance.aspx
  4. See Kimberly Tripp’s article on www.sqlskills.com
  5. Point out some of the options available.
  6. Run and explain demo scripts.
  7. http://blog.ola.hallengren.com/blog/_archives/2008/1/1/3440068.html
  8. If time, demo SQL Server alerts.