Presentation is loading. Please wait.

Presentation is loading. Please wait.

Anil Desai Austin CodeCamp 2008.  Anil Desai ◦ Independent consultant (Austin, TX) ◦ Author of several SQL Server books ◦ Instructor, “Implementing and.

Similar presentations


Presentation on theme: "Anil Desai Austin CodeCamp 2008.  Anil Desai ◦ Independent consultant (Austin, TX) ◦ Author of several SQL Server books ◦ Instructor, “Implementing and."— Presentation transcript:

1 Anil Desai Austin CodeCamp 2008

2  Anil Desai ◦ Independent consultant (Austin, TX) ◦ Author of several SQL Server books ◦ Instructor, “Implementing and Managing SQL Server 2005” (Keystone Learning) ◦ Info: http://AnilDesai.net or Anil@AnilDesai.net http://AnilDesai.netAnil@AnilDesai.net

3 I. Performance Monitoring Overview II. Monitoring SQL Server III. Using SQL Profiler IV. Using the Database Engine Tuning Advisor V. Managing Processes, Locking, and Deadlocks

4 Developing processes and approaches for performance optimization

5  Best Practices: ◦ Optimize for real-world workloads ◦ Monitor/review performance regularly ◦ Focus on specific issues Establish a baseline Identify bottlenecks Make one change at a time Measure performance Repeat (if desired)

6 Windows System Monitor Alerts (Performance-Based) System/OS SQL Profiler / SQL Trace Activity Monitor / SQL Server Agent Alerts Dynamic Management Views (DMVs) SQL Server Database Engine Tuning Advisor Query Execution Plans Query- Level

7 Using various SQL Server features to monitor database activity

8  Overviews of SQL Server usage ◦ Can export to Excel or PDF  Server-Level Report Examples: ◦ Server Dashboard ◦ Memory Consumption ◦ Activity – All Block Transactions ◦ Activity – Top Sessions ◦ Performance – Batch Execution Statistics ◦ Performance – Top Queries by Average CPU ◦ Object Execution Statistics

9  Examples: ◦ Disk Usage ◦ All Transactions ◦ All Blocking Transactions ◦ Index Usage Statistics ◦ Top Transactions by Age ◦ Schema Changes History  New reports added in Service Packs ◦ Ability to use custom reports

10  Windows Event Logs / Event Viewer ◦ Application and System Event Logs  SQL Server Management Studio ◦ SQL Server Logs  Can configure max. # of log files ◦ SQL Server Agent Error logs  Can configure logging levels (Errors, Warnings, Information)  Using the Log File Viewer ◦ Can Export / Load log information ◦ Can search for specific errors/messages

11  Purpose: ◦ Monitoring and troubleshooting ◦ View server state and performance details ◦ Returns relational result sets  Scopes: ◦ Server level ◦ Database level

12  Examples: ◦ Database Engine  Sys.DM_DB_File_Space_Usage ◦ Indexes  Sys.DM_DB_Index_Operational_Stats  Sys.DM_DB_Index_Physical_Stats ◦ I/O Related  Sys.DM_IO_Pending_IO_Requests  Sys.DM_IO_Virtual_File_Stats ◦ Common Language Runtime ◦ Database Mirroring ◦ Transactions

13  Data Collected: ◦ System Information (MSINFO) ◦ Windows Event Logs ◦ SQL Server configuration  Command-Line Utility (SQLDiag.exe) ◦ Stores output to files ◦ Configuration file: SQLDiag.xml ◦ Can run as a service (/R) ◦ Can run in continuous mode

14 Monitoring SQL Server Activity

15  Purpose / Features: ◦ GUI for managing SQL Trace ◦ Monitor important events ◦ Capture performance data / resource usage ◦ Replaying of workloads / transactions ◦ Identifying performance bottlenecks ◦ Correlation of data with System Monitor ◦ Workloads for Database Tuning Advisor  Examples: ◦ Generate a list of the 100 slowest queries ◦ Monitor all failed logins (Security)

16  SQL Profiler Terminology ◦ Trace Definitions ◦ Events ◦ Columns ◦ Filters  Creating and Managing SQL Traces ◦ SQL Profiler (GUI) ◦ System Stored Procedures (Transact-SQL)  Trace Templates (Built-In) ◦ Standard (Default), SP_Counts ◦ TSQL, TSQL_Duration, TSQL_Grouped,TSQL_Replay, TSQL_SPs ◦ Tuning

17  Groupings: ◦ Event Categories ◦ Event Classes ◦ Events  Examples: ◦ TSQL ◦ Stored Procedures ◦ Performance ◦ Errors and Warnings ◦ Security auditing Event Categories Event Classes Events

18  Specify the details to be recorded  Columns can be ordered and grouped  Values can be filtered  Examples of Columns: ◦ StartTime / EndTime ◦ TextData ◦ Duration ◦ Resource Usage (CPU, Reads, Writes) ◦ Information: User, Database, App. Names

19  Interactive ◦ Good for “live” monitoring of small sets of data  Trace Files (*.trc) ◦ Can enable file rollover based on size ◦ “Server processes trace data” option  Trace table ◦ Will automatically create the table ◦ Can set maximum number of rows  Scheduling of traces (stop time)

20  Launching SQL Profiler  Connecting to a database instance  Configuring output options  Create a trace definition  Specifying events, columns, and filters  Running and viewing a trace

21  Creating new templates  Scripting trace definitions  Extracting SQL Server Events ◦ Transact-SQL Events ◦ ShowPlan Events ◦ Deadlock Events

22  Purpose / Goal: ◦ Correlate server performance with database performance  Process: ◦ Define and start a counter log ◦ Define and start a SQL Profiler trace ◦ Import Performance Data in SQL Profiler  Required Trace properties ◦ StartTime ◦ EndTime

23  Can monitor local or remote computers  Performance Statistics: ◦ Objects ◦ Counters ◦ Instances  Modes: ◦ System Monitor ◦ Performance Logs and Alerts  Counter Logs  Trace Logs  Alerts

24 Analyzing workloads to optimize physical database structures

25  Can make performance-related recommendations  Replaces the “Index Tuning Wizard”  Evaluates Physical Design Structures (PDS) ◦ Indexes (clustered, non-clustered) ◦ Indexed Views ◦ Partitions  Numerous analysis options  Output ◦ Generates modification scripts ◦ Generates Reports for later analysis

26  Files ◦ Transact-SQL Files ◦ XML Files ◦ Should represent commonly-used queries  SQL Profiler Trace Files / Tables ◦ Use Tuning built-in trace template ◦ Events:  Transact-SQL Batch  Remote Procedure Call (RPC) ◦ Columns: Event Class and Text Data

27  Limit tuning time  Tuning Options ◦ Allowed Physical Design Structures (PDS) ◦ Keep all/specific existing objects ◦ Maximum storage space ◦ Online or offline recommendations ◦ Partitioning

28  Reports can be exported to XML files  Report Examples: Workload analysis Column accessTable access View-Table Relations Statement costEvent frequency Index Usage (current / recommended)

29  Process: ◦ Generate a workload (file or table) ◦ Select tuning options ◦ Run the analysis ◦ View reports ◦ Save and/or apply recommendations  Running the DTA: ◦ Database Engine Tuning Advisor Application (GUI) ◦ Dta.exe command-line utility

30 Troubleshooting common SQL Server performance problems

31  Processes ◦ Interactive users  SQL Server Management Studio ◦ Applications (Connection Pooling)  SQL Profiler  Database Engine Tuning Advisor  Replication  Service Broker  Process IDs < 50 are system-related

32  SQL Server Activity Monitor ◦ Processes (connected users) ◦ Locks (by Process / by Object) ◦ Filtering options ◦ Auto-refresh option  System Stored Procedures / Views ◦ Sys.DM_Exec_Sessions ◦ Sys.DM_Exec_Requests ◦ Sys.SysProcesses ◦ sp_who / sp_who2

33  Process Information ◦ Current Process ID: @@SPID ◦ Session Options: DBCC USEROPTIONS  Killing Processes ◦ KILL ProcessID [WITH STATUSONLY]  Viewing Last Activity ◦ DBCC INPUTBUFFER(ProcessID) ◦ DBCC OUTPUTBUFFER(ProcessID)

34  Coordinates multiple accesses to the same data  Ensures ACID Properties for transactions (Atomic, Consistent, Independent, Durable)  Contention can reduce performance  Locking granularity: ◦ Row-Level, Page-Level, Table-Level, etc.  Lock Modes: ◦ Shared, Exclusive, etc.  Lock escalation

35  Blocking ◦ When transaction(s) must wait for a lock on a resource ◦ LOCK_TIMEOUT setting (default = wait forever)  Locking Models: ◦ Pessimistic ◦ Optimistic

36  Balance of concurrency (performance) vs. consistency ◦ Affects SELECT queries ◦ SET TRANSACTION ISOLATION LEVEL  Transaction Isolation Levels ◦ READ UNCOMMITTED ◦ READ COMMITTED (default) ◦ REPEATABLE READ ◦ SERIALIZABLE  Row-Versioning: ◦ ALLOW_SNAPSHOT_ISOLATION ◦ READ_COMMITTED_SNAPSHOT

37  Activity Monitor  SQL Profiler ◦ Locks Event Category  System Monitor: ◦ SQL Server  Locks Object  System Views ◦ Sys.DM_Tran_Locks ◦ Sys.DM_Exec_Requests  System Stored Procedures ◦ sp_Lock

38  Deadlocks: ◦ Two or more tasks permanently block each other based on resource locks ◦ Default resolution is within 5 seconds  Deadlock victim ◦ Transaction is rolled-back ◦ Process receives a 1205 error  Example: ◦ Process 1 locks the Customers table and requires access to the Orders Table ◦ Process 2 locks the Orders table and requires access to the Customers Table

39  Minimize transaction times ◦ Commit / Rollback transactions as quickly as possibly ◦ Avoid user-related time within a transaction  Access objects in a consistent order  Change the transaction isolation level ◦ Use a lower level isolation level, if appropriate ◦ Use snapshot-based isolation levels

40  Deadlock priorities: ◦ SET DEADLOCK_PRIORITY (LOW, NORMAL, HIGH, integer)  Deadlock resolution: ◦ Lower priority is killed first ◦ If equal priorities, least expensive transaction becomes the victim ◦ Application or user should attempt to re-run the transaction

41  SQL Server Error Log  SQL Profiler ◦ Locks Event Category  Lock:Deadlock Chain  Lock:Deadlock  Deadlock Graph ◦ Events Extraction Trace Property ◦ Export deadlock XML (.xdl) file  Viewing Deadlock Files ◦ SQL Server Management Studio (File  Open  SQL Deadlock Files (*.xdl)

42

43  Resources from Anil Desai ◦ Web Site (http://AnilDesai.net)http://AnilDesai.net ◦ E-Mail: Anil@AnilDesai.netAnil@AnilDesai.net ◦ ReportingServicesGuru.com ReportingServicesGuru.com ◦ Keystone Learning Course: “Microsoft SQL Server 2005: Implementation and Maintenance (Exam 70-431)”

44


Download ppt "Anil Desai Austin CodeCamp 2008.  Anil Desai ◦ Independent consultant (Austin, TX) ◦ Author of several SQL Server books ◦ Instructor, “Implementing and."

Similar presentations


Ads by Google