elearning Event ESSENTIAL SKILLS FOR SQL SERVER DBAS Session 3
Session 3 Session 1 DBAs: What, Why and How SQL Server Engine and Security Session 2 File / Database Management Disaster Recovery Session 3 SQL Server Performance Basics Maintenance
SQL Server as an Application How SQL Server Leverages RAM The Plan Cache: Execution Plans. The Buffer Pool: Database data/pages. Workspace Memory: Buckets for query output. Other Caches: Object/User/Data. Connection Details, etc. SQL Server is a Windows Application SQL Server is under same restrictions as other Apps. Pre-Emptive Multi-Tasking Quantum / Time Slice SQL Server HAS to YIELD
SQL Server as an Application How SQL Server Leverages RAM The Plan Cache: Execution Plans. The Buffer Pool: Database data/pages. Workspace Memory: Buckets for SQL query Server output. has to wait its Other Caches: Object/User/Data. turn and play nice with Connection Details, etc. system resources just like all other processes and SQL Server is under same restrictions as applications. other Apps. Pre-Emptive Multi-Tasking Quantum / Time Slice SQL Server HAS to YIELD SQL Server is a Windows Application
Walkthrough: A Simple Query Statistics Size, Shape, Distribution Help SQL Server anticipate
Walkthrough: A Simple Query Behind the Scenes: Network Transport / TDS Authentication Authorization Parsing Get or Generate an Execution Plan Statistics Size, Shape, Distribution Help SQL Server anticipate
Performance is Complex SQL Server Has its Own, Internal, Scheduler Manages Concurrent Operations within SQL Server. Translates Quantums / Slices from OS into tasks and operations internally. Keeps CAREFUL tabs and records on all of the operations currently in processes. Also logs information about what SQL Server is waiting on. Insanely Complex
Making Sense of Performance Overly-Simplified View of Performance: Problems Manifest when Data > RAM Small DBs on Servers with Large RAM are rarely a problem. Larger Databases and Tip of the Iceberg
Making Sense of Performance Overly-Simplified View of Performance: Problems Manifest when Data > RAM Small DBs on Servers with Large RAM are rarely a problem. Larger Databases and Tip of the Iceberg
Introduction to Indexes
Introduction to Indexes
Introduction to Indexes
Indexes are Narrower
Indexes are Narrower
Indexes and Balance Trees 1-1,750 1,751 3,500 1-875 876 1,750 1,751 2,626 2,267 3,500 1-875 876 1,750 1,751 2,626 2,267 3,500
Clustered and Covering Indexes Clustered Indexes Only One Per Table. Defines LOGICAL order of data in your tables. Optimized for Ranged Queries. Covering Indexes Cover everything needed to satisfy queried portion of a single table. Typically Wide by virtue of covering multiple columns. Almost act as specialized copies of your tables for given/specific queries.
SQL Server Performance: Maintenance
Statistics Maintenance Statistics What Creates them? You can explicitly (CREATE STATISTICS command). Or, SQL Server can create them automatically. Maintenance UPDATE STATISTICS command OR: EXEC sp_updatestats Run it manually in each database (including system dbs) OR: EXEC sp_msforeachdb @command1 = 'EXEC?..sp_updatestats' Updating Stats DOES impose some perf overhead.
Indexes - Fragmentation The new phone book is here! The new phone book is here! Navin R Johnson (The Jerk)
Index Defragmentation Two Ways to Defragment: Reorganize (Defragment) Indexes: Typically used when indexes are < 30% Fragmented. Online Operation queries won t time-out. Rebuild Indexes: Typically done when fragmentation > 30% OFFLINE Operation: - Queries CAN/WILL time-out Enterprise Edition: Offers Online Index Rebuilds Some Limitations / Tradeoffs
Indexes Rebuilding and Reorganizing Detecting Fragmentation DBCC SHOWCONTIG or dm_db_index_physical_stats Addressing Fragmentation REORDER ALTER INDEX <index_name>... WITH REORDER (2005+) DBCC INDEXDEFRAG (2000/Deprecated) REBUILD ALTER INDEX <index_name>... WITH REBUILD (2005+) DBCC DBREINDEX (2000/Deprecated)
Index Maintenance: How to Cheat Michelle Ufford s Index Defrag Script (v4.0) Free Awesome
Troubleshooting: Tools/Techniques
Available Performance Tuning Tools Performance Monitor Low Level Windows/OS (and Application) Instrumentation SQL Server Profiler SQL Server-level Tracing/Instrumentation DMVs and WAIT_STATS Query What SQL Server is doing, or has waited on. Detailed information on current execution details, connections, cache/memory management, and handles to execution plans. SQL Server Execution Plans HIGHLY Detailed Representations of Execution Plans
Performance Monitor (Perfmon)
SQL Server Profiler
Watcher Effect Logging Performance Data: Adds Performance Overhead when using Profiler/Perfmon Recommendations: Beware Feedback Loops. Always save Profiler traces to.trc files. Watcher Effect Can add up to 5% over head. Usually negligible But WATCH for it on heavily used Production Servers
WAIT STATS and DMVs Books Online Documents GOBS of different Execution Based DMVs
SQL Server Execution Plans
SQL Server Execution Plans
SQL Server Execution Plans
Conclusion Additional Resources / Links: http://updates.sqlservervideos.com