Course Topics

Post on 25-Feb-2016

27 views 2 download

description

Course Topics. 04 | Manage Data. George Squillace | Senior Technical Trainer – New Horizons Great Lakes Richard Currey | Senior Technical Trainer – New Horizons United. Module 4 Overview. Backups and Backup Strategies Restores and Recovery Move Databases and Database Files - PowerPoint PPT Presentation

Transcript of Course Topics

Course Topics

Administering SQL Server 2012 Jump Start01 | Install and Configure SQL Server 04 | Manage Data

02 | Maintain Instances and Databases 05 | Implement Security

03 | Performance Optimization and Troubleshooting 06 | High Availability Options

Click to edit Master subtitle style

04 | Manage DataGeorge Squillace | Senior Technical Trainer – New Horizons Great LakesRichard Currey | Senior Technical Trainer – New Horizons United

Module 4 Overview• Backups and Backup Strategies• Restores and Recovery• Move Databases and Database Files• Ensure Database Integrity• Indexes, Statistics, and Maintenance

Topic: Backups and Backup Strategies

Topic: Backups and Backup Strategies• User Database Recovery Models• Backup Statements and Typical Options• Backup Integrity Testing• System Database Backups

User Database Recovery ModelsRecovery Model Details

Full • Point in time recovery• Failed media recovery

Bulk-logged • Interim recovery model used to reduce logging

• Point in time recovery is not available within bulk options

Simple (truncate log on checkpoint)

• Log backups are not available, no point in time recovery

• Small databases or databases that can be rebuilt from other source data

Backup Statements and Typical OptionsStatement Typical Options

– BACKUP DATABASE– BACKUP LOG

– FORMAT– CHECKSUM– COPY_ONLY– WITH INIT/NOINIT– WITH DIFFERENTIAL– WITH MIRROR TO– COMPRESSION– NOTRUNCATE– NORECOVERY– CONTINUE_AFTER_ERROR

Backup Integrity Testing• RESTORE VERIFYONLY FROM device• RESTORE HEADERONLY FROM device• RESTORE FILELISTONLY FROM device• RESTORE LABELONLY FROM device

System Database Backups• Vital to the recovery of the instance• Certain system database corruptions cause the

failure of the SQL Server or SQL Server Agent Services

• Don’t change the system database recovery models

DEMOExecuting BACKUP Statements and Testing Backup Integrity

Topic: Restores and Recovery

Topic: Restores and Recovery• Recovery Process and Phases• Types of Restores• Restore Statements and Typical Options• System Database Restores–Special Considerations

Recovery Process and Phases• Recovery phases– Data copy– Redo– Undo

• Recovery process– Don’t make it worse…calm yourself!– Tail log backup (remember the demo?)– Restore full-database backup– Restore most recent differential backup– Restore all logs from the most recent differential– Restore the tail of the log and recover the database

Types of Restores• Complete database restore in simple recovery• Complete database restore in full recovery• System database restore• File restore• Online restore• Piecemeal restore• Page restore

Restore Statements and Typical OptionsStatements Typical Options

• RESTORE DATABASE – WITH RECOVERY / NORECOVERY

– WITH FILE = 1– WITH REPLACE– WITH MOVE– WITH STANDBY

•RESTORE LOG – WITH STANDBY– WITH STOPAT = time– WITH STOPATMARK /

STOPBEFOREMARK

System Database Restores–Special Considerations• Recovering master when not corrupt• Recovering master when corrupt• Recovering model when corrupt• Recovering MSDB when corrupt• Recovering resource when corrupt• “Recovering” TempDB when corrupt

DEMORestoring and Recovering a Database and Point-in-Time Recovery

Topic: Move Databases and Database Files

Topic: Move Databases and Database Files

• Moving and Copying Entire Databases to Other Instances

• Relocate Database Files Within an Instance• System Databases Require Special Treatment

Moving and Copying Databases to Other Instances• SSMS / sp_detach_db / SSIS• CREATE Database … FOR ATTACH (which now

supercedes sp_attach_db)• Requires the use of logical filenames (use

sys.database_files)

Relocate Database Files Within an Instance• ALTER DATABASE• Requires the Use of Logical Filenames (use

sys.database_files)

System Databases Require Special Treatment• Moving master requires setting startup options in

SQL Server Configuration Manager• Other system databases require the use of ALTER

DATABASE and a SQL Server Service restart

DEMOMoving a User Database

Topic: Ensure Database Integrity

Topic: Ensure Database Integrity• Overview of DBCC Statements• DBCC CHECKDB Execution Options• DBCC CHECKDB Repair Options

Overview of DBCC Statements• Corruption is rare but possible• There are Many DBCC commands– Informational statements• DBCC OPENTRAN

– Validation statements• DBCC CHECKDB

–Maintenance statements• DBCC FREEPROCCACHE

–Miscellaneous statements• DBCC TRACEON/TRACEOFF

DBCC CHECKDB Execution Options• Purpose of DBCC CheckDB is to validate database integrity• When DBCC CheckDB executes, it also spawns:

– DBCC CHECKALLOC– DBCC CHECKTABLE– DBCC CHECKCATALOG

• PHYSICAL_ONLY• NOINDEX• EXTENDED_LOGICAL_CHECKS• TABLOCK• ALL_ERRORMSGS• NO_INFOMSGS• ESTIMATEONLY

DBCC CHECKDB Repair Options• Back up the database before performing any DBCC repair• But if you have to repair…

– The database must be in single user mode (ALTER DATABASE)– REPAIR_REBUILD

• Causes no loss of data integrity within the database• Rebuilds indexes and deallocates corrupt pages• Does not involve data loss• Only works in certain circumstances

– REPAIR_ALLOW_DATA_LOSS• Repair should absolutely be the last resort• Database damage is likely• If the database is in Emergency Repair mode (ALTER DATABASE) special repairs are

attempted with this option

• Make sure that the original cause of the corruption is resolved

DEMOUsing DBCC CheckDB

Topic: Indexes, Statistics, and Maintenance

Topic: Indexes, Statistics, and Maintenance

• Table Structures• What Is An Index?• What Are Statistics?• Index Fragmentation• Index and Statistics Maintenance

Table Structures• Heap– Default table structure– No order of table pages (logically or physically)– No order of rows within a page

• Clustered Table– Imposed when a clustered index is created

• Potential result of creating a primary key constraint, a unique constraint or (unlikely) the CREATE CLUSTERED INDEX statement

– Logical ordering of table pages– Physical ordering of rows within a page– Only one clustered index per table

What Is an Index?• List of sorted values–May or may not impose uniqueness of values

• Stored in pages outside of the table• Reading index pages on well-designed indexes is

often more efficient in locating rows than reading the whole table (scan)

• Clustered index vs. a non-clustered index• Created by using constraint creation or CREATE

INDEX

What Are Statistics?• Cardinality–number of members in a set• (Distribution) statistics objects sample data to help obtain

cardinality estimates for tables and indexed views• Help determine an optimal execution plan– May aid in index selection and query processing– Join type (nested loop, hash)– Join order (table 1, table 2, or table 2, table 1)

• Statistics are auto or manually created– May include a sampling of values or all values

• Statistics become outdated as data changes

Index Fragmentation• Fragmentation is internal and/or external

– Internal• The inefficient use of space within database pages

– External• Pages spread (non-contiguously) within a data file

• Some amount of internal fragmentation may be desirable– Internal fragmentation can be controlled with the FILLFACTOR and PAD_INDEX

options of the Create Index and Create Table statements

• External fragmentation is never desirable• Fragmentation is determined by:

– GUI– sys.dm_db_index_physical_stats (DMF)

• Checks fragmentation database-wide, table-wide, for a specific index or a specific partition

Index and Statistics Maintenance• Index maintenance

– ALTER INDEX … REORGANIZE– ALTER INDEX … REBUILD

• Enterprise Edition Index Maintenance features– ALTER INDEX … ALL

• Statistics maintenance– Auto create and update options– AUTO_UPDATE_STATISTICS_ASYNC– Forceful update with sp_UpdateStats

• Tools– Maintenance plans in SSIS– T-SQL agent jobs

DEMODetermining Fragmentation and Performing Index Maintenance

©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.