Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 16: Performing Ongoing Database Maintenance

Similar presentations


Presentation on theme: "Module 16: Performing Ongoing Database Maintenance"— Presentation transcript:

1 Module 16: Performing Ongoing Database Maintenance
Course 6231B Module 16: Performing Ongoing Database Maintenance Module 16 Performing Ongoing Database Maintenance

2 Module 16: Performing Ongoing Database Maintenance
Course 6231B Module Overview Module 16: Performing Ongoing Database Maintenance Ensuring Database Integrity Maintaining Indexes Automating Routine Database Maintenance

3 Lesson 1: Ensuring Database Integrity
Course 6231B Lesson 1: Ensuring Database Integrity Module 16: Performing Ongoing Database Maintenance Discussion: Ensuring Database Integrity Overview of DBCC CHECKDB DBCC CHECKDB Options DBCC CHECKDB Repair Options Demonstration 1A: DBCC CHECKDB

4 Discussion: Ensuring Database Integrity
Course 6231B Discussion: Ensuring Database Integrity Module 16: Performing Ongoing Database Maintenance What is database integrity? What techniques are you currently using to check and maintain database integrity? Discuss with the audience what database integrity means. Make sure that they understand that there are two levels of integrity that are known as physical and logical integrity. Physical integrity: The data pages are written to the physical storage as SQL Server requested and can also be read correctly. Logical integrity: The data within the pages is logically correct. For example, every index entry points to the correct data row and every data row is referenced by an index entry. Point out that without regular checking database integrity cannot be ensured. Backup does NOT check the integrity, it only checks the page checksums, when WITH CHECKSUM is specified. Also make it clear that the CHECKSUM database option is important, but that only the checksum is checked when the data is read, or when WITH CHECKSUM is specified during the backup. Archive data is not read frequently, which can lead to corrupt data within the database that will not be found for months, if it is not checked. Also point out that WITH CHECKSUM at backup level, you cannot ensure complete database integrity. Question: What is database integrity? Answer: Physical and logical integrity of the database. The pages are intact and linked correctly and the data in the pages is consistent. Question: What techniques are you currently using to check and maintain database integrity? Answer: Answers will vary but DBCC CHECKDB should be one of the options.

5 Overview of DBCC CHECKDB
Course 6231B Overview of DBCC CHECKDB Module 16: Performing Ongoing Database Maintenance Checks logical and physical integrity in the database Allocation of all pages in the database Consistency of tables and indexes Consistency of the catalog of the database Link level consistence for FILESTREAM objects Service Broker objects Offers repair options Some options permit data loss Runs online using an internal database snapshot Should be run frequently Synchronize executions with your backup strategy, to be able to recover corruption Go through the checks that DBCC CHECKDB performs: DBCC CHECKALLOC to check the consistency of page allocations. DBCC CHECKTABLE for every table in the database to check their consistency. DBCC CHECKCATALOG to check the database catalog. In addition it checks the links to FILESTREAM objects and the Service Broker environment when used. Point out that it is a online operation by default since SQL Server 2005. Explain that despite DBCC CHECKDB has repair options but that it is not always possible to repair the database without data loss. Restoring the database is often the best option for repair. Question: Why is it vital to run DBCC CHECKDB regularly? Answer: Because it is the only way to ensure database integrity. Running it regularly prevents situation with corrupt data that cannot be recovered anymore, even with a backup as the corruption also exists on them. Mention that backups copy pages without really being concerned about the logical consistency of the database between pages. Ask students what they would think about a strategy involving a DBCC CHECKDB, followed by a backup with checksum, also followed by a restore verifyonly. Is that overkill? (If it's possible, it's a fairly good safety option but a restore on another server would be better than the verifyonly option). Reference: DBCC CHECKDB (Transact-SQL): DBCC CHECKALLOC (Transact-SQL): DBCC CHECKTABLE (Transact-SQL): DBCC CHECKCATALOG (Transact-SQL):

6 Module 16: Performing Ongoing Database Maintenance
Course 6231B DBCC CHECKDB Options Module 16: Performing Ongoing Database Maintenance Option Description PHYSICAL_ONLY Only checks the physical integrity with less overhead NOINDEX Does not perform logical checks on nonclustered indexes EXTENDED_LOGICAL_CHECKS Performs additional logical checks of indexed views, spatial and XML indexes TABLOCK Uses locks instead of database snapshots ALL_ERRORMSGS Returns all error messages instead of the default action that returns the first 200 NO_INFOMSGS Returns only error messages and no informational messages ESTIMATEONLY Estimates the amount of tempdb space that is required for execution Briefly explain the available options in the table. Refer to the SM for details of each option. Explain that NOINDEX specifies that intensive checks of nonclustered indexes for user tables should not be performed. This also decreases the overall execution time but does not affect system tables because integrity checks are always performed on system table indexes Point out that PHYSICAL _ONLY is often used on production systems because it causes a much shorter run- time on large databases. EXTENDED_LOGICAL_CHECKS is only performed when the database is in compatibility level 100 (SQL Server 2008) or above. TABLOCK uses locks to keep consistency during the checks on the tables and not an internal database snapshot.. You might mention the TABLERESULTS option. It returns results in a table and is quite useful. It is, however, an undocumented option which means it is not supported and could change in the future. Question: Which DBCC CHECKDB option might be used on very large production systems? Answer: PHYSICAL_ONLY as it covers most of the possible corruptions and then perform a full check less frequently. Reference: DBCC CHECKDB (Transact-SQL):

7 DBCC CHECKDB Repair Options
Course 6231B DBCC CHECKDB Repair Options Module 16: Performing Ongoing Database Maintenance Database needs to be in SINGLE_USER mode DBCC CHECKDB output shows minimum option for recovery REPAIR_REBUILD for repairs that can be done without data loss REPAIR_ALLOW_DATA_LOSS involves data loss Consider restoring a database instead of allowing data loss Explain that the DBCC CHECKDB output provides both the errors and the actions to take. Explain the 2 options and that the database needs to be in SINGLE_USER mode for both options: REPAIR_REBUILD rebuilds the corrupt pages based on the information of other non corrupted pages. REPAIR_ALLOW_DATA_LOSS will almost always produce a data loss. Emphasize that it is also recommended to backup the database before using any repair option. Emphasize that repairing the database is the last resort. Typically it is the better to restore a database. Stress that a corrupt database suggests storage layer issues that need to be resolved or the corruption will probably happen again. Question: Why would it be preferable to restore a database rather than using REPAIR_ALLOW_DATA_LOSS? Answer: Because no data loss occurs. Reference: DBCC CHECKDB (Transact-SQL):

8 Demonstration 1A: DBCC CHECKDB
Course 6231B Demonstration 1A: DBCC CHECKDB Module 16: Performing Ongoing Database Maintenance In this demonstration, you will see how to use the different options for the DBCC CHECKDB command High-level Steps Revert the virtual machines as per the instructions in D:\6231B_Labs\Revert.txt. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, click SQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_16_PRJ\6231B_16_PRJ.ssmssln and click Open. Open and execute the 00 – Setup.sql script file from within Solution Explorer. Open the 11 – Demonstration 1A.sql script file. Follow the instructions contained within the comments of the script file. Notes for emphasis on specific steps: Step 1: Note the output and point to the last message which indicates that there were no errors. Step 2: Note the difference in output. Only error messages would appear with this option. Step 3: Note that this database was backed up in a corrupted state. Step 4: Note that 4 errors are returned and note that the last line of output tells you the minimum repair level required. The table Orders has issues. Step 5: Note the error 824 is returned. This is a commonly seen error that relates to disk subsystem problems. Step 6: Note that the error might only apply to particular pages in the table. Try to access a specific order and note that the row is returned because the query does not access the corrupted page or pages. Step 7: Note this is an emergency option and should only be used as an absolutely last resort. Step 10: Note that there is a foreign key between the Orders and the [Order Details] tables based on Order ID. This means that an order must exist for each order detail. We’ll query for order details entries that do not have matching orders. (note how much data was lost).

9 Lesson 2: Maintaining Indexes
Course 6231B Lesson 2: Maintaining Indexes Module 16: Performing Ongoing Database Maintenance How Indexes Affect Performance Types of SQL Server Indexes Index Fragmentation FILLFACTOR and PADINDEX Ongoing Maintenance of Indexes Online Index Operations Updating Statistics Demonstration 2A: Index Maintenance

10 How Indexes Affect Performance
Course 6231B How Indexes Affect Performance Module 16: Performing Ongoing Database Maintenance Table Scan SQL Server reads all table pages Start by mentioning that indexing is covered in detail in course 6232B: Implement a Microsoft SQL Server R2 database. Only a brief discussion of the key points is included here. Make sure that you do not spend too long discussing indexing in this course. It would be easy to lose a whole day discussing indexing rather than the time allocated to one lesson. Use this slide to explain that SQL Server accesses data by using indexes or by scanning all the data pages in a table. Give an example of selecting a single order based on an OrderID from the orders table. Without an index SQL Server has to scan all orders in the orders table to find the requested order. With an index on OrderID, SQL Server can use the index to find the data row very efficiently. Point out that the difference can be substantial. For example, access might involve 3-4 pages instead of hundreds or thousands. Emphasize the fact that creating an index is not required; however, accessing data is usually considerably slower without indexes. Mention that SQL Server sometimes makes its own temporary indexes to improve query performance. However, doing so is up to the optimizer and beyond the control of the database administrator or programmer, so these temporary indexes will not be discussed in this module. When discussing how SQL Server accesses data, do not go into great depth at this point. Question: When might a table scan be more efficient than using the index? Answer: An example would be when all the data in a table needs to be accessed in no particular order. Reference: Table and Index Organization: Which is Faster: Index Access or Table Scan?: Index SQL Server uses index pages to find rows

11 Types of SQL Server Indexes
Course 6231B Types of SQL Server Indexes Module 16: Performing Ongoing Database Maintenance Indexes are organised as B-Trees (Balanced Trees) Clustered index has data pages in the leaf level Nonclustered index has pointer to data rows in leaf level Explain that SQL Server indexes are so called balanced trees. The index consists of index pages that hold the data needed to navigate through the index. This data defines ranges that point to pages in the next index level. Give an example of searching for an OrderID with a value of in an index for OrderID. In the root page SQL Server searches for the range the value is within. The entry for the range in the root page points to a index page in the next level. In the next level the range is divided into smaller ranges again pointing to pages on the following level. This is done, up to a point where every row can be referenced on its own. This level is called the Leaf node. Explain that all pages within a level are double linked to each other. Point out that a index in SQL Server typically is very flat, which means that it can address a lot of tables with only a view rows. Explain that SQL Server has 2 types of indexes, and that the difference is the leaf level. Clustered index: The clustered index has the actual data directly in the leaf node. Because of the index organization the data is therefore logically sorted by the clustering key. Because of this SQL Server can use a clustered index not only to find rows quickly, but can also scan the leaf node ordered, which returns the whole table sorted by the clustering key. Ensure that students understand that there can be only a single clustered index because it determines the logical ordering of the data. id index_id root_page Root Index Page Intermediate Level Index Pages Leaf Nodes

12 Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane.
Course 6231B Notes Page Over-flow Slide. Do Not Print Slide. See Notes pane. Module 16: Performing Ongoing Database Maintenance Nonclustered index: With a nonclustered index the leaf level contains the index keys and a pointer. To retrieve the rows SQL Server has to follow the pointer. Note that because a nonclustered index stores only the pointers, there can be more than 1 nonclustered index on a table. Don’t go any deeper into the discussion of indexes as this is only an overview and point out that in deep discussion on indexes, indexing on performance, included columns, indexed views and so on is covered in the 6232B training. Question: What is the main difference between clustered and nonclustered indexes? Answer: The clustered index has the data in the leaf level and the nonclustered index has pointer to the data in the leaf level. Reference: Clustered Index Structures: Nonclustered Index Design Guidelines:

13 Module 16: Performing Ongoing Database Maintenance
Course 6231B Index Fragmentation Module 16: Performing Ongoing Database Maintenance How does fragmentation occur? SQL Server reorganizes index pages when data modification causes index pages to split Index fragmentation is the inefficient use of pages within an index. Fragmentation occurs over time as data is modified. Review the types of fragmentation that are described in the SM. Question: Why does fragmentation affect performance? Answer: If pages are only half full, twice as many pages need to be read to access the same amount of data. Reference: Reorganizing and Rebuilding Indexes: Types of fragmentation: Internal – pages are not full External – pages are out of logical sequence Detecting fragmentation SQL Server Management Studio – Index Properties System function - sys.dm_db_index_physical_stats

14 FILLFACTOR and PADINDEX
Course 6231B FILLFACTOR and PADINDEX Module 16: Performing Ongoing Database Maintenance Free space can be left in indexes, including clustered indexes FILLFACTOR PADINDEX We can avoid the overhead of page splits by leaving empty space on each page when we first create an index, including a clustered index. We do this by specifying a FILLFACTOR value. FILLFACTOR defaults to 0, which means "fill 100%". Any other value (including 100) is taken as the percentage of how full we'd like each page to be. For the example in the slide, this means 70% full and 30% free space on each page. FILLFACTOR only applies to leaf level pages in an index. PAD_INDEX is an option that, when enabled, causes the same free space to be allocated in the non-leaf levels of the index. Question: While we could avoid many page splits by setting a FILLFACTOR of 50, what would be the downside of doing this? Answer: Reading the whole table would now need twice as many pages to be read. I/O is typically the biggest bottleneck in SQL Server systems today so this might be very counter-productive. Question: When would a FILLFACTOR of 100 be very useful? Answer: Read-only data. Question: What is the significance of applying a FILLFACTOR on a clustered index versus a non-clustered index? Answer: FILLFACTOR on a clustered index is applied to the data pages, so it's really applying FILLFACTOR to a table. FILLFACTOR on a non-clustered index applies to pages of clustering keys, or row pointers if a heap. Reference: ALTER INDEX (Transact-SQL): CREATE INDEX (Transact-SQL): ALTER TABLE Person.Person ADD CONSTRAINT PK_Person_BusinessEntityID PRIMARY KEY CLUSTERED ( BusinessEntityID ASC ) WITH (PAD_INDEX = OFF, FILLFACTOR = 70); GO

15 Ongoing Maintenance of Indexes
Course 6231B Ongoing Maintenance of Indexes Module 16: Performing Ongoing Database Maintenance REBUILD Rebuilds the whole index Needs free space in database Performed as a single transaction with potential requirement for a large amount of transaction log space As indexes become fragmented over time, administrators need to defragment them. Explain that there are 2 option for doing this: Rebuilding an index and Reorganizing an index. Rebuild: Rebuilding an index drops and re-creates the index. This removes fragmentation, reclaims disk space by compacting the pages based on the specified or existing fill factor setting, and reorders the index rows in contiguous pages. When the ALL option is specified, all indexes on the table are dropped and rebuilt in a single operation. Point out that because this is done in a single transaction a lot of transaction log space is needed for large indexes. But if the database is in BULK_LOGGED or SIMPLE recovery model this transaction can be done in a minimal logged operation which requires much less space in transaction log and runs faster. Emphasize that free space also needs to be available to rebuild the index. Reorganize: Reorganizing an index uses minimal system resources. It defragments the leaf level of clustered and nonclustered indexes on tables and views by physically reordering the leaf-level pages to match the logical, left to right order of the leaf nodes. Reorganizing also compacts the index pages. Compaction is based on the existing fill factor value. Point out that for heavy fragmented indexes (> 30%) rebuilding is the fastest option normally. Question: What is typically the best option to defragment big indexes and tables (clustered indexes)? Answer: Reorganizing as it uses less resources. Reference: Reorganizing and Rebuilding Indexes: REORGANIZE Sorts the pages and is always online Less transaction log usage Can be interrupted but still retain work performed to that point ALTER INDEX CL_LogTime ON dbo.LogTime REBUILD; ALTER INDEX ALL ON dbo.LogTime REORGANIZE;

16 Online Index Operations
Course 6231B Online Index Operations Module 16: Performing Ongoing Database Maintenance Indexes can be created, rebuilt and dropped online Allows concurrent user access to the underlying table and indexes Only needs short term shared locks at begin and end of the operation and Schema locks during the operation Typically slower than equivalent offline operation but allows user access Explain that Online Index Operations are features of the Enterprise and Datacenter edition of SQL Server. Briefly explain the process how an index is rebuilt online based on the discussion in the SM. Emphasize that because of the extra work needed to be done during an online operation, online operations are typically slower then their offline counterparts, but it allows users to access and change the data, which is important in many scenarios. Explain that there are exceptions for operations that cannot be performed online. For example rebuilding clustered indexes with LOB data. Question: When would online index operations be most important? Answer: When there are no available maintenance hours for the database and user access is needed for 24 hours a day. Reference: Performing Index Operations Online: How Online Index Operations Work: Guidelines for Performing Online Index Operations: ALTER INDEX IX_Contact_ Address ON Person.Contact REBUILD WITH ( PAD_INDEX = OFF, FILLFACTOR = 80, ONLINE = ON, MAXDOP = 4 );

17 Module 16: Performing Ongoing Database Maintenance
Course 6231B Updating Statistics Module 16: Performing Ongoing Database Maintenance As data changes, distribution statistics become outdated Statistics can be updated automatically or on demand Automatic update set through database option and should be enabled Mention that statistics are normally managed automatically by SQL Server. Stress that the option to update statistics automatically should be enabled except in very rare circumstances. Explain that statistics can also be updated on demand. With UPDATE STATISTICS all statistics on a table are updated. Mention that sp_updatestats can be used to update all statistics in a database. Question: Why might you decide to update statistics out of hours instead of automatically? Answer: That there is smaller chance that they get outdated during peak hours and need to be rebuild then. Reference: UPDATE STATISTICS (Transact-SQL): Using Statistics to Improve Query Performance: sp_updatestats (Transact-SQL): Option Description AUTO_UPDATE_STATISTICS Database option that allows SQL Server to update statistics automatically UPDATE STATISTICS Statement to update statistics on a table or specified statistics on demand sp_updatestats Updates all statistics in the database

18 Demonstration 2A: Index Maintenance
Course 6231B Demonstration 2A: Index Maintenance Module 16: Performing Ongoing Database Maintenance In this demonstration you will see: How to view index fragmentation How to reorganize indexes High-level Steps If Demonstration 1A was not performed: Revert the virtual machines as per the instructions in D:\6231B_Labs\Revert.txt. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, click SQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_16_PRJ\6231B_16_PRJ.ssmssln and click Open. Open and execute the 00 – Setup.sql script file from within Solution Explorer. Open and execute 11 – Demonstration 1A.sql script file Open the 21 – Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file. Notes for emphasis on specific steps: Step 2: Note that declaring a primary key creates a clustered index unless you specify nonclustered. Step 4: Note the avg_fragmentation_in_percent and avg_page_space_used_in_percent. Step 6: Note the avg_fragmentation_in_percent and avg_page_space_used_in_percent again. Step 8: Note the avg_fragmentation_in_percent and avg_page_space_used_in_percent again.

19 Lesson 3: Automating Routine Database Maintenance
Course 6231B Lesson 3: Automating Routine Database Maintenance Module 16: Performing Ongoing Database Maintenance Overview of SQL Server Database Maintenance Plans Monitoring Database Maintenance Plans Demonstration 3A: Configuring a Database Maintenance Plan

20 Overview of SQL Server Database Maintenance Plans
Course 6231B Overview of SQL Server Database Maintenance Plans Module 16: Performing Ongoing Database Maintenance Help database administrators to schedule core maintenance tasks Create one or more SQL Server Agent jobs Use SSIS to perform tasks Can be created manually rather than via the wizard Explain that the Maintenance Plan Wizard schedules core maintenance tasks to ensure that your database is regularly backed up, performs well, and is checked for inconsistencies. The Maintenance Plan Wizard creates one or more SQL Server Agent jobs that perform these maintenance tasks automatically at scheduled intervals. You can schedule many maintenance tasks to run automatically, including: Backing up the database and transaction log files. Database and log backups can be retained for a specified period. Running SQL Server Agent jobs that perform a variety of actions. Compacting data files by removing empty database pages. Performing internal consistency checks of the data and data pages within the database to make sure that a system or software problem has not damaged data. Reorganizing the information on the data pages and index pages by rebuilding indexes. Updating index statistics to make sure the query optimizer has up-to-date information about the distribution of data values in the tables. Note that maintenance plans can use one schedule for all tasks or individual schedules for each task. Question: What types of maintenance tasks should be automated? Answer: Will vary, but will include backups, integrity checks, and index-related tasks. Reference: Maintenance Plan Wizard: Maintenance Plans: 20

21 Monitoring Database Maintenance Plans
Course 6231B Monitoring Database Maintenance Plans Module 16: Performing Ongoing Database Maintenance Real time monitoring through Job Activity Monitor Execution results stored in msdb and can also be Written to a text file Sent to an Operator Cleanup tasks are used to implement retention Explain that Maintenance Plans are implemented using SQL Agent jobs running SSIS packages. Because of this real time monitoring can be done using the Job Activity Monitor. The results generated by the maintenance tasks are written to the maintenance plan tables sysmaintplan_log and sysmaintplan_log_detail in the msdb database. In addition text reports can be written to the file system and also be sent automatically to Operators defined in SQL Server Agent. Note that cleanup tasks exist, that can be used to implement a retention policy for Backup files, job history, Maintenance Plan Report files and msdb entries. Question: Are maintenance plan history records cleaned up automatically? Answer: No a retention policy needs to be implemented as part of a maintenance plan. Reference: Maintenance Plans: 21

22 Demonstration 3A: Configuring a Database Maintenance Plan
Course 6231B Demonstration 3A: Configuring a Database Maintenance Plan Module 16: Performing Ongoing Database Maintenance In this demonstration, you will see: How to create and execute a Maintenance Plan How to review the history for a Maintenance Plan High-level Steps If Demonstration 1A was not performed: Revert the virtual machines as per the instructions in D:\6231B_Labs\Revert.txt. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, click SQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_16_PRJ\6231B_16_PRJ.ssmssln and click Open. Open and execute the 00 – Setup.sql script file from within Solution Explorer. Open and execute 11 – Demonstration 1A.sql script file Open the 21 – Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file. Notes for emphasis on specific steps: Step 3: Note the available scheduling options and click Change. Step 8: Note that the plan executed successfully and click Close. 22

23 Lab 16: Ongoing Database Maintenance
Course 6231B Lab 16: Ongoing Database Maintenance Module 16: Performing Ongoing Database Maintenance Exercise 1: Check database integrity using DBCC CHECKDB Exercise 2: Correct index fragmentation Exercise 3: Create a database maintenance plan Challenge Exercise 4: Investigate table lock performance (Only if time permits) Exercise 1 There has been a disk failure in the I/O subsystem. The disk has been replaced but you want to check the consistency of your existing databases. You will execute DBCC CHECKDB to verify the logical and physical integrity of all databases on the Proseware instance. Exercise 2 You have identified fragmentation in a number of tables in the MarketDev database and you are sure that performance is decreasing as the amount of fragmentation increases. You will rebuild the indexes for any of the main database tables that are heavily fragmented. Exercise 3 You have also identified a degradation of performance in the application when proper index maintenance has not been performed. You want to ensure that there is an early detection of any consistency issues in the MarketDev database and that the index maintenance is automatically executed on a scheduled basis. To make sure this regular maintenance occurs, you will create a Database Maintenance plan to schedule these operations on a weekly basis. Challenge Exercise 4 (Only if time permits) While DBCC CHECKDB runs quite quickly, you are interested in the performance difference that might be achieved by using table locks instead of database snapshots during DBCC CHECKDB operations. If you have time, you will investigate the performance differences. Logon information Virtual machine 623XB-MIA-SQL User name AdventureWorks\Administrator Password Pa$$w0rd Estimated time: 45 minutes

24 Module 16: Performing Ongoing Database Maintenance
Course 6231B Lab Scenario Module 16: Performing Ongoing Database Maintenance There has been a disk failure in the I/O subsystem. The disk has been replaced but you want to check the consistency of your existing databases. You will execute DBCC CHECKDB to verify the logical and physical integrity of all databases on the Proseware instance. You have identified fragmentation in a number of tables in the MarketDev database and you are sure that performance is decreasing as the amount of fragmentation increases. You will rebuild the indexes for any of the main database tables that are heavily fragmented. You have also identified a degradation of performance in the application when proper index maintenance has not been performed. You want to ensure that there is an early detection of any consistency issues in the MarketDev database and that the index maintenance is automatically executed on a scheduled basis. To make sure this regular maintenance occurs, you will create a Database Maintenance plan to schedule these operations on a weekly basis. Mention that the scenario is quite large and that only the part of the scenario that relates to the core exercises is shown. For the challenge exercise, the scenario is: While DBCC CHECKDB runs quite quickly, you are interested in the performance difference that might be achieved by using table locks instead of database snapshots during DBCC CHECKDB operations. If you have time, you will investigate the performance differences.

25 Module 16: Performing Ongoing Database Maintenance
Course 6231B Lab Review Module 16: Performing Ongoing Database Maintenance If you need to perform additional options that are not provided in the database maintenance plan wizard, what options could you use? If you need to execute a maintenance plan with timing that cannot be accommodated by a single schedule, what can you do? Question: If you need to perform additional options that are not provided in the database maintenance plan wizard, what options could you use? Answer: Edit the plan in BIDS and add the extra options, or add scheduled tasks in SQL Server Agent. Question: If you need to execute a maintenance plan with timing that cannot be accommodated by a single schedule, what can you do? Answer: Add another schedule.

26 Module Review and Takeaways
Course 6231B Module Review and Takeaways Module 16: Performing Ongoing Database Maintenance Review Questions Best Practices Review Questions Question: What regular tasks should be implemented for read only databases? Answer: Backup and consistency checking. Updating statistics or rebuilding/reorganizing indexes is not possible on read-only databases and should be done before making the database read-only. Question: What option should you consider using when running DBCC CHECKDB against large production databases? Answer: PHYSICAL_ONLY for regular executions and perform full checks less regularly. Best Practices Run DBCC CHECKDB regularly Synchronize DBCC CHECKDB with your backup strategy Consider RESTORE before repairing if corruption occurs Defragment your indexes when necessary Update statistics on schedule, if you don’t want it to occur during normal operations Use Maintenance Plans to implement regular tasks


Download ppt "Module 16: Performing Ongoing Database Maintenance"

Similar presentations


Ads by Google