22
Pro SQL Server 2012 Administration ■ ■ ■ Ken Simmons Sylvester Carstarphen

Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

  • Upload
    lephuc

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

Pro SQL Server 2012 Administration

■ ■ ■

Ken Simmons Sylvester Carstarphen

Page 2: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

Pro SQL Server 2012 Administration

Copyright © 2012 by Ken Simmons and Sylvester Carstarphen

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

ISBN 978-1-4302-3915-4

ISBN 978-1-4302-3916-1

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

President and Publisher: Paul Manning Lead Editor: Jonathan Gennick Technical Reviewers: Jonathan Kehayias, Jorge Segarra and Don Watters Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Louise Corrigan, Morgan Ertel,

Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh

Coordinating Editors: Anita Castro and Stephen Moles Copy Editor: Lori Cavanaugh Compositor: Mary Sudul Indexer: SPi Global Cover Designer: Anna Ishchenko

Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com.

For information on translations, please e-mail [email protected], or visit www.apress.com.

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales.

The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.

(eBook)

Page 3: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

iii

To my wife Susan and son Nathan

–Ken Simmons

To my loving wife Kimberly

–Sylvester Carstarphen

Page 4: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

v

Contents at a Glance

Contents..................................................................................................................vii

About the Authors................................................................................................ xxiii

PART 1: Introducing Microsoft SQL Server 2012 ......................................................1

■ Chapter 1: New Features Overview......................................................................3

■ Chapter 2: Pre-Installation Considerations........................................................15

■ Chapter 3: Choosing a High-Availability Solution ..............................................33

PART 2: Getting Started ..........................................................................................59

■ Chapter 4: Installing and Upgrading ..................................................................61

■ Chapter 5: Post-Installation ...............................................................................99

PART 3: Administering Microsoft SQL Server 2012..............................................125

■ Chapter 6: Multi-Server Administration...........................................................127

■ Chapter 7: Managing Security Within the Database Engine.............................159

■ Chapter 8: Working with Database Objects .....................................................183

■ Chapter 9: Indexing for Performance...............................................................223

■ Chapter 10: Managing Backups.......................................................................257

■ Chapter 11: Restore and Recovery Strategies .................................................283

■ Chapter 12: Automating Routine Maintenance ................................................319

Page 5: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

vi

PART 4: Troubleshooting and Tuning....................................................................353

■ Chapter 13: Monitoring Your Server ................................................................355

■ Chapter 14: Auditing SQL Server......................................................................389

■ Chapter 15: Extended Events Interface............................................................403

■ Chapter 16: Managing Query Performance......................................................421

■ Chapter 17: Secrets to Excelling as a Professional DBA..................................451

■ Chapter 18: What’s Next? ................................................................................463

Index.....................................................................................................................471

Page 6: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

vii

Contents

Contents at a Glance.................................................................................................v About the Authors................................................................................................ xxiii

PART 1: Introducing Microsoft SQL Server 2012 ......................................................1

■ Chapter 1: New Features Overview......................................................................3

Availability Enhancements .......................................................................................3 Online Index Rebuilds ......................................................................................................3 Indirect Checkpoints ........................................................................................................4 Clustering.........................................................................................................................4 AlwaysOn .........................................................................................................................4

Manageability Enhancements ..................................................................................5 Extended Events ..............................................................................................................5 Database Restores...........................................................................................................6 Contained Databases .......................................................................................................7

Programmability Enhancements ..............................................................................7 Functions .........................................................................................................................8 Sequence Numbers .........................................................................................................9 OFFSET and FETCH ........................................................................................................11 THROW...........................................................................................................................12 EXECUTE WITH RESULT SETS ........................................................................................13

Summary ................................................................................................................14

■ Chapter 2: Pre-Installation Considerations........................................................15

Choosing a SQL Server Edition ...............................................................................15 Enterprise Edition ..........................................................................................................16 Standard Edition ............................................................................................................17

Page 7: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

viii

Developer Edition...........................................................................................................17 Business Intelligence Edition.........................................................................................18 Web Edition....................................................................................................................18

SQL Server 2012 Licenses ......................................................................................18 Determining Hardware Requirements ....................................................................19 Determining CPU Needs..........................................................................................21

Deriving a Baseline Specification ..................................................................................21 Consider Future Utilization.............................................................................................21 Example Using the CPU Questions.................................................................................22

Disk Subsystems ....................................................................................................22 Database Sizing .............................................................................................................23 Estimating Size from a Baseline ....................................................................................24 Estimating Size Based Upon Row and Column Sizes ....................................................24

Determining RAID Levels ........................................................................................25 Understanding RAID Levels............................................................................................25 RAID 0 ............................................................................................................................26 RAID 1 ............................................................................................................................26 RAID 5 ............................................................................................................................26 RAID 10 ..........................................................................................................................26 Choosing Your RAID Level and Laying Out Your Files ....................................................27

Final Disk Storage Configuration............................................................................28 Determining Memory Requirements.......................................................................28 Choosing the Server ...............................................................................................29 SQL Server Consolidation .......................................................................................29 Consolidation with Virtual Servers .........................................................................31 Summary ................................................................................................................32

■ Chapter 3: Choosing a High-Availability Solution ..............................................33

What Exactly Is High Availability Anyway? ............................................................33 Failover Clustering .................................................................................................34

Key Terms......................................................................................................................34 Failover Clustering Overview .........................................................................................34 Implementation..............................................................................................................36

Page 8: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

ix

Pros and Cons of Failover Clustering.............................................................................37 Database Mirroring.................................................................................................37

Key Terms......................................................................................................................37 Database Mirroring Overview ........................................................................................38 Implementation..............................................................................................................38 Snapshots for Reporting ................................................................................................39 High-safety mode ..........................................................................................................39 High-Performance Mode................................................................................................40 Pros and Cons of Database Mirroring ............................................................................41

Copying Data with Log Shipping.............................................................................42 Key Terms......................................................................................................................42 Log Shipping Overview ..................................................................................................42 Implementation..............................................................................................................42 Restoring to the Secondary Server ................................................................................44 Pros and Cons of Log Shipping ......................................................................................44

Making Data Available Through Replication...........................................................45 Key Terms......................................................................................................................45 Replication Overview .....................................................................................................45 Snapshot Replication .....................................................................................................46 Transactional Replication ..............................................................................................47

Updateable Subscriptions..........................................................................................47 Peer-to-Peer Replication ...........................................................................................49

Merge Replication..........................................................................................................50 Pros and Cons of Replication .........................................................................................51

AlwaysOn................................................................................................................51 Key Terms......................................................................................................................52 AlwaysOn Overview .......................................................................................................52 Implementation..............................................................................................................53 Pros and Cons of AlwaysOn ...........................................................................................55

Other High-Availability Techniques ........................................................................55 High Availability Feature Comparison ....................................................................56 Summary ................................................................................................................57

Page 9: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

x

PART 2: Getting Started ..........................................................................................59

■ Chapter 4: Installing and Upgrading ..................................................................61

User Accounts.........................................................................................................62 Preparation and Prerequisites................................................................................62 SQL Server Installation Center................................................................................63

Planning.........................................................................................................................64 Installation .....................................................................................................................65 Maintenance ..................................................................................................................66 Tools ..............................................................................................................................67 Resources ......................................................................................................................68 Advanced .......................................................................................................................69 Options...........................................................................................................................70

Installing Your First Instance .................................................................................70 Getting Started...............................................................................................................70 Choosing Your Features.................................................................................................70 Configuring the Instance................................................................................................72 Configuring the Database Engine ..................................................................................72 Validating and Installing ................................................................................................73

Installing More Than One Instance.........................................................................74 Preparing to Install Another Instance ............................................................................75 Getting Your System Ready ...........................................................................................75 Configuring the Instance................................................................................................76

Command-Line Installation ....................................................................................77 Learning the Parameters ...............................................................................................77 Passing Parameters to the Installer...............................................................................79 Building the Command ..................................................................................................80

Choosing the Level of Silence ...................................................................................80 Specifying the Action and the Components...............................................................80 Configuring the Instance ...........................................................................................81 Specifying the Data Directories .................................................................................82

Executing the Command................................................................................................82 Configuration File Installation ................................................................................83

Page 10: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xi

SysPrep Installation ...............................................................................................86 Preparing the Image ......................................................................................................87 Completing the Image....................................................................................................88

Upgrading to Microsoft SQL Server 2012 ...............................................................89 Upgrade Tools................................................................................................................89

Microsoft SQL Server 2012 Upgrade Advisor ............................................................89 Upgrade Assistant .....................................................................................................90

Upgrade Strategies ........................................................................................................91 In-Place Upgrade .......................................................................................................91 Side-by-Side Upgrade ...............................................................................................93 The Detach/Attach Migration Method........................................................................94 Backup/Restore Migration Method............................................................................94 Copy Database Wizard Migration Method .................................................................95

Post-Upgrade Procedures..............................................................................................96 Changing Compatibility Level ........................................................................................97 Checking Object Integrity...............................................................................................97 Correct Row and Page Counts .......................................................................................97 Setting the Page Verification Method ............................................................................98 Updating Statistics.........................................................................................................98

Summary ................................................................................................................98

■ Chapter 5: Post-Installation ...............................................................................99

SQL Server Configuration Manager ........................................................................99 SQL Server Services ....................................................................................................100 SQL Server Network Configuration ..............................................................................104 SQL Native Client Configuration...................................................................................110

Configuring the Instance ......................................................................................112 Viewing Configuration Settings....................................................................................112 Viewing Advanced Options ..........................................................................................112 Specifying Maximum and Minimum Server Memory...................................................113 Enabling Address Windows Extensions .......................................................................115 Specifying the Backup Compression Default...............................................................115 Enabling Login Failure Auditing ...................................................................................117 Enabling Dedicated Administrator Connections...........................................................118

Page 11: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xii

Enabling Use of the CLR (Common Language Runtime) ..............................................118 Enabling a Query Governor Cost Limit .........................................................................119 xp_cmdshell ................................................................................................................119 Miscellaneous Configuration Options ..........................................................................119

Preproduction Tasks.............................................................................................121 Server Tasks ................................................................................................................121 Database Tasks ...........................................................................................................122 Maintenance and Monitoring .......................................................................................123

Summary ..............................................................................................................124

PART 3: Administering Microsoft SQL Server 2012..............................................125

■ Chapter 6: Multi-Server Administration...........................................................127

Policy-Based Management...................................................................................127 Manually Creating a Policy ..........................................................................................128 Exporting Current State As Policy ................................................................................136 Importing a Predefined Policy......................................................................................138

Central Management Servers ...............................................................................141 Creating a Central Management Server.......................................................................141 Running Multi-Server Queries .....................................................................................144 Configuring Multi-Server Query Options ......................................................................146 Evaluating Policies.......................................................................................................147

SQL Dependency Reporting ..................................................................................151 Summary ..............................................................................................................157

■ Chapter 7: Managing Security Within the Database Engine.............................159

Security Language................................................................................................159 Principals .....................................................................................................................160 Securables ...................................................................................................................161 Schemas ......................................................................................................................161

Creating SQL Server Principals ............................................................................161 Creating Logins for SQL Server....................................................................................161 Creating SQL Server Logins for Windows Principals ...................................................162

Page 12: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xiii

Creating SQL Server-Authenticated Logins .................................................................163 Associating Logins with Certificates and Asymmetric Keys ........................................163 Linking Credentials to Logins ......................................................................................164 SQL Server-Level Roles ...............................................................................................165 Creating Server-Level Roles ........................................................................................165 Adding and Removing Logins to Server-Level roles ....................................................166

Database Security.................................................................................................166 Creating Database Users .............................................................................................166 Database Roles ............................................................................................................168

Understanding Fixed Roles......................................................................................168 Creating a Database Role ........................................................................................168

Application Roles .........................................................................................................169 Contained Databases ...................................................................................................169

Securables............................................................................................................170 Managing Server Securables.......................................................................................170

Granting Access to Server Securables ....................................................................170 Denying Access to Server Securables.....................................................................170

Managing Database Securables ..................................................................................171 Granting Access to Database Securables................................................................171 Denying Access to Database Securables ................................................................172

Understanding Schema Securables.............................................................................172 Defaulting User Schemas ........................................................................................172 Creating Schemas ...................................................................................................173

Permissions..........................................................................................................174 Types of Permissions...................................................................................................174 Permission Grouping....................................................................................................175 Managing Permissions ................................................................................................175

Encryption ............................................................................................................176 Encrypting Data Using Certificate Encryption ..............................................................176 Encrypting Data Using Asymmetric Keys.....................................................................178 Encrypting Data Using Symmetric Keys.......................................................................179 Extensible Key Management .......................................................................................181 Transparent Data Encryption .......................................................................................181

Summary ..............................................................................................................182

Page 13: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xiv

■ Chapter 8: Working with Database Objects .....................................................183

Working with Contained Databases......................................................................183 Working with System Databases..........................................................................186 Working with Database Snapshots.......................................................................187

Creating a Database Snapshot ....................................................................................188 Viewing and Querying a Snapshot ...............................................................................188 Reverting a Database to a Database Snapshot............................................................190

Working with Tables.............................................................................................191 Default Constraints ......................................................................................................191 Primary Key Constraints ..............................................................................................193 Unique Constraints.......................................................................................................194 Foreign Key Constraints...............................................................................................195 Check Constraints........................................................................................................197 Sparse Columns...........................................................................................................198 Compression................................................................................................................199 Partitions......................................................................................................................201 Temporary Tables ........................................................................................................202

Working with Views..............................................................................................203 Updateable Views ........................................................................................................204 Indexed Views..............................................................................................................205

Working with Synonyms.......................................................................................207 Working with Stored Procedures .........................................................................210 Working with Functions........................................................................................213

Scalar-Valued Functions..............................................................................................214 Table-Valued Functions ...............................................................................................215

Working with Triggers..........................................................................................217 DML Triggers ...............................................................................................................217 DDL Triggers ................................................................................................................218 Logon Triggers.............................................................................................................219

Working with the Common Language Runtime ....................................................220 Summary ..............................................................................................................222

Page 14: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xv

■ Chapter 9: Indexing for Performance...............................................................223

Index Concepts and Structures ............................................................................223 Heaps...........................................................................................................................223 Clustered Indexes ........................................................................................................223 Nonclustered Indexes ..................................................................................................224 Structure of Indexes and the Heap ..............................................................................224

Clustered Index Structure........................................................................................224 Nonclustered Index Structure..................................................................................226 Heap Structure ........................................................................................................227

Indexes Created by Constraints ...................................................................................227 Primary Indexes.......................................................................................................227 Unique Indexes ........................................................................................................227

Other Ways to Categorize Indexes ...............................................................................227 Composite Indexes ..................................................................................................228 Filtered Indexes .......................................................................................................228 XML Indexes ............................................................................................................228 Compressed Indexes ...............................................................................................228 Columnstore Indexes ...............................................................................................228

Other Index Concepts and Terminology.......................................................................229 Include Columns ......................................................................................................229 Covering Queries .....................................................................................................229 Searchable Arguments ............................................................................................229 Cardinality ...............................................................................................................230

Creating Indexes via T-SQL...................................................................................230 Creating Clustered and Nonclustered Indexes.............................................................230

Considerations When Creating Clustered Indexes...................................................230 Considerations When Creating Nonclustered Indexes.............................................231 Creating an Index.....................................................................................................232

Creating Unique and Primary Key Indexes...................................................................235 Creating Filtered Indexes.............................................................................................236 Creating XML Indexes ..................................................................................................240

Primary XML Indexes...............................................................................................241 Secondary XML Indexes ..........................................................................................241

Creating Columnstore Indexes.....................................................................................241

Page 15: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xvi

Post-Index Creation ..............................................................................................242 Performance of Insert, Update, and Delete Statements ..............................................242 Useful Dynamic Management Views ...........................................................................244

SYS.DM_EXEC_QUERY_STATS ................................................................................244 SYS.DM_DB_lNDEX_USAGE_STATS ........................................................................245 Missing Index Dynamic Management Views ...........................................................245

Putting It All Together ..........................................................................................246 Setting Up the Scenario ...............................................................................................246 Table Scans .................................................................................................................247 Clustered Index Seeks .................................................................................................248 Covering Your Queries .................................................................................................250 Indexing JOIN Criteria ..................................................................................................253 Filtered Indexes ...........................................................................................................255

Summary ..............................................................................................................256

■ Chapter 10: Managing Backups.......................................................................257

Recovery Models ..................................................................................................257 Backup Architecture.............................................................................................258 Backup Types .......................................................................................................259

Full Backups ................................................................................................................260 Differential Backups ....................................................................................................261 Transaction Log Backups ............................................................................................262 Partial Backups............................................................................................................263 File Backups ................................................................................................................264 Copy-Only Backups......................................................................................................265

Backup Compression............................................................................................265 Logical Backup Devices........................................................................................267 The GUI Backup Interface .....................................................................................270 Backups from T-SQL .............................................................................................275 Using Encryption ..................................................................................................277 Backing Up the System Databases .......................................................................278 Backup History .....................................................................................................279 Summary ..............................................................................................................281

Page 16: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xvii

■ Chapter 11: Restore and Recovery Strategies .................................................283

Restore Vocabulary ..............................................................................................283 The Importance of Recovery Models ....................................................................284 Practicing Your Recovery Strategy ......................................................................285 Types of Restores .................................................................................................286 Restoring Full Backups.........................................................................................287 Restoring Transaction Logs..................................................................................288 Restoring Differential Backups.............................................................................289 Restoring Files and Filegroups .............................................................................289 Restoring Pages ...................................................................................................291 Piecemeal Restores ..............................................................................................291 Restoring Snapshots.............................................................................................292 RESTORE HEADERONLY .........................................................................................292 RESTORE FILELISTONLY ........................................................................................293 RESTORE VERIFYONLY...........................................................................................293 Online Recoveries .................................................................................................293 Restore Considerations ........................................................................................294

Utilizing Filegroups for Faster Restores.......................................................................294 Preparing for Hardware Failures..................................................................................294 Recovering from Scratch .............................................................................................295

Recovery Examples ..............................................................................................296 Example 1: The Piecemeal Restore .............................................................................296

Creating the Example Database ..............................................................................296 Reviewing Execution Plans......................................................................................297

Backing Up the Tail End of the Transaction Log ..........................................................298 Restoring the Database ...........................................................................................298 Reviewing Execution Plans Without Nonclustered Indexes.....................................301 Attempting to Bring the Database Online ................................................................303 Completing the Recovery.........................................................................................304 Verifying Correct Execution Plans............................................................................306

Example 2: Restoring a Compressed and Encrypted Database ...................................306 Setting Up the Example ...........................................................................................307 Restoring Certificates ..............................................................................................310 Restoring Transaction Logs Using SQL Server Management Studio .......................310

Page 17: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xviii

Example 3: Restoring System Databases ....................................................................316 Restoring the Master Database from Single User Mode .........................................316 Rebuilding the master Database Using REBUILDDATABASE ...................................317

Summary ..............................................................................................................318

■ Chapter 12: Automating Routine Maintenance ................................................319

Database Mail .......................................................................................................319 Database Mail Configuration Wizard............................................................................319 Configuring Database Mail Using T-SQL......................................................................328 Sending Database Mail ................................................................................................329 Database Mail Cleanup Procedures.............................................................................331

SQL Server Agent..................................................................................................331 Operators .....................................................................................................................331 Enabling SQL Server Agent Notifications.....................................................................333 Alerts ...........................................................................................................................334 Jobs .............................................................................................................................338 Proxies .........................................................................................................................346

Maintenance Plans ...............................................................................................348 Maintenance Plan Wizard ............................................................................................349 Maintenance Plan Design Tab .....................................................................................350 Maintenance Plan Tasks..............................................................................................351

Summary ..............................................................................................................352

PART 4: Troubleshooting and Tuning....................................................................353

■ Chapter 13: Monitoring Your Server ................................................................355

Baseline Your Server ............................................................................................355 Choosing What to Collect .............................................................................................355 Capturing and Storing Your Baseline Data...................................................................356

Familiarizing Yourself with the Performance Monitor .........................................357 Monitoring Your CPU ............................................................................................359

Windows Counters That Indicate CPU Utilization.........................................................362 SQL Server Counters That Impact CPU ........................................................................363

Page 18: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xix

DMVs for Monitoring CPU.............................................................................................364 Monitoring Your Memory......................................................................................367

Memory Usage in SQL Server ......................................................................................367 Counters to Watch .......................................................................................................367 Memory with Windows Counters .................................................................................370 Memory with SQL Server Counters..............................................................................371 Memory with DMVs and DBCC Commands..................................................................372

Monitoring Disk IO................................................................................................374 Disk IO with Windows Counters...................................................................................376 Disk IO with SQL Server Counters................................................................................377

Monitoring Miscellaneous Counters and DMVs ....................................................378 Monitoring Wait Types with DMVs ...............................................................................378 Monitoring Your Server with Activity Monitor ..............................................................379 Capturing SQL Server PerfMon Counters Using DMVs.................................................380 Management Data Warehouse.....................................................................................380 Leveraging the SQL Server Profiler..............................................................................380

Using Server-Side Tracing....................................................................................383 Automating Your Monitoring ................................................................................386 Summary ..............................................................................................................387

■ Chapter 14: Auditing SQL Server......................................................................389

Choosing Your Audit Type.....................................................................................389 Creating SQL Server Audits with T-SQL ................................................................390 Creating Server Audit Specifications....................................................................390

Server-Level Action Groups .........................................................................................391 Testing Your Server Audit Specification ......................................................................392

Creating Database Audit Specifications ...............................................................393 Database-Level Audit Action Groups ...........................................................................394 Database-Level Audit Actions......................................................................................394 Testing Your Database Audit Specification..................................................................395

Creating SQL Server Audits Using the GUI ............................................................396 Creating a Database Audit Specification Using the GUI ...............................................398 Reviewing Audit Files Using SQL Server Management Studio.....................................399

Page 19: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xx

Audit-Related Startup and Shutdown Problems...................................................400 Failure to Start .............................................................................................................400 Forced Shutdowns.......................................................................................................400

Useful SQL Server Audit Objects...........................................................................400 Other Auditing Methods........................................................................................401 Summary ..............................................................................................................401

■ Chapter 15: Extended Events Interface............................................................403

Key Terms.............................................................................................................403 SQL Trace..............................................................................................................404 Creating an Event Session ....................................................................................405 Viewing Events .....................................................................................................413

Watching Live Data ......................................................................................................413 XEL Files ......................................................................................................................415 Configuring Columns ...................................................................................................415 Advanced Manipulation ...............................................................................................417

Summary ..............................................................................................................420

■ Chapter 16: Managing Query Performance......................................................421

Correlating Profiler and Performance Monitor .....................................................421 Finding Problematic Queries Using DMVs ............................................................423 Finding Similar Queries Using DMVs ....................................................................426 Optimizing for Specific Parameter Values............................................................429 Forcing Index Seeks .............................................................................................431 Forcing Index Scans .............................................................................................433 Forcing a Specific Execution Plan ........................................................................433 Adding Hints Through Plan Guides .......................................................................435

Creating a Plan Guide ..................................................................................................435 Validating a Plan Guide ................................................................................................437

Managing Resources with the Resource Governor...............................................439 Resource Pools ............................................................................................................439 Workload Groups .........................................................................................................441 Classifier Function .......................................................................................................443

Page 20: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xxi

Monitoring Resource Governor.............................................................................445 Performance Counters .................................................................................................445 Trace Events ................................................................................................................446 Views ...........................................................................................................................447

Summary ..............................................................................................................449

■ Chapter 17: Secrets to Excelling as a Professional DBA..................................451

Be Good at What You Do .......................................................................................451 Face Reality .................................................................................................................451

Accept That You Are Not the Best............................................................................451 Accept and Learn from Criticism.............................................................................451 Accept That Things Won’t Always Go Your Way ......................................................452 Accept That Some Goals Are Not Realistic ..............................................................452

Build Your Reputation ..................................................................................................453 Go Above and Beyond...........................................................................................454 Communicate Effectively ......................................................................................454

Talk to Your Target Audience.......................................................................................454 Know When You aren’t Getting Through..................................................................455

Know When They Don’t Care .......................................................................................455 Be a Good Listener.......................................................................................................455

Remain Calm Under Pressure...............................................................................456 Prepare for Pressure Situations...................................................................................456 Deal with Pressure Situations......................................................................................456 Wrap Up the Pressure Situation...................................................................................458

Be an Effective Leader ..........................................................................................458 Make Tough Decisions.................................................................................................459 Make Others Around You Better ..................................................................................459 Learn to Delegate.........................................................................................................460

Staying at the Top.................................................................................................460 Saying Goodbye ....................................................................................................461 Summary ..............................................................................................................461

Page 21: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

■ CONTENTS

xxii

■ Chapter 18: What’s Next? ................................................................................463

Ongoing Experimentation and Learning ...............................................................463 Sharing Feedback With Microsoft ........................................................................464 Podcasts ...............................................................................................................464 Blogs.....................................................................................................................464 Free Training Events.............................................................................................465 Social Networking ................................................................................................465 SQL Support Options.............................................................................................466

Free Support ................................................................................................................466 Product Solution Center...........................................................................................466 Microsoft Community Resources.............................................................................467

Paid Support ................................................................................................................468 Advisory Services ........................................................................................................468

Web Sites Dedicated to SQL Server ......................................................................469 Summary ..............................................................................................................469

Index.....................................................................................................................471

Page 22: Pro SQL Server 2012 Administration - Springer978-1-4302-3916-1/1.pdf · iii To my wife Susan and son Nathan –Ken Simmons To my loving wife Kimberly –Sylvester Carstarphen

xxiii

About the Authors

■ Ken Simmons is a Database Administrator and Developer specializing in Microsoft SQL Server. He is an author for multiple SQL Server websites and books including Pro SQL Server 2008 Administration, Pro SQL Server 2008 Mirroring, Pro SQL Server 2008 Policy-Based Management, and Pro SQL Server 2012 Administration. He currently holds certifications for MCP, MCAD, MCDBA, MCTS for SQL Server 2005, and MCITP for SQL Server 2008.

■ Sylvester Carstarphen is the manager of a global database administration team for a consumer technology protection company where he brings his vast SQL Server Database Administration experience into their rapidly growing and changing environment. Sylvester started his database administration career in 2003 and has rapidly excelled in his career every since. His exceptional leadership and technical skills have enabled him to lead teams (as a working DBA manager) at a Fortune 500 Company, the leading CRM Company in the Automobile Industry, and now the premier provider of consumer technology protection services. Sylvester has a Master’s Degree in Computer Science and is an author of Pro SQL Server 2008 Administration.