SQL Server: Performance Tuning and Optimization: Module: Locking and Concurrency Lesson: Blocking Student Lab Manual
SQL Server: Performance Tuning and Optimization: Module: Locking and Concurrency Lesson: Blocking Student Lab Manual
SQL Server: Performance Tuning and Optimization: Module: Locking and Concurrency Lesson: Blocking Student Lab Manual
Lesson: Blocking
This training package is proprietary and confidential, and is intended only for uses described in the training materials. Content
and software is provided to you under a Non-Disclosure Agreement and cannot be distributed. Copying or disclosing all or any
portion of the content and/or software included in such packages is strictly prohibited.
The contents of this package are for informational and training purposes only and are provided "as is" without warranty of any
kind, whether express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular
purpose, and non-infringement.
Training package content, including URLs and other Internet Web site references, is subject to change without notice. Because
Microsoft must respond to changing market conditions, the content should not be interpreted to be a commitment on the part
of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. Unless
otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events
depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address,
logo, person, place, or event is intended or should be inferred.
Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights
covering subject matter in this document. Except as expressly provided in written license agreement from
Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights,
or other intellectual property.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under
copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or
transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for
any purpose, without the express written permission of Microsoft Corporation.
For more information, see Use of Microsoft Copyrighted Content at
http://www.microsoft.com/en-us/legal/intellectualproperty/Permissions/default.aspx
DirectX, Hyper-V, Internet Explorer, Microsoft, Outlook, OneDrive, SQL Server, Windows, Microsoft Azure,
Windows PowerShell, Windows Server, Windows Vista, and Zune are either registered trademarks or trademarks of
Microsoft Corporation in the United States and/or other countries. Other Microsoft products mentioned herein
may be either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other
countries. All other trademarks are property of their respective owners.
Table of Contents
LAB 1: LOCKING AND CONCURRENCY
Introduction
In this lab, you will simulate a production environment with blocking issues and deadlock
issues. You will practice how to troubleshoot these problems.
Objectives
After completing this lab, you will be able to:
Identify blocking and analyze blocking issues.
Use Extended Events to troubleshoot blocking and deadlock issues.
Understand read-committed snapshot behavior and optimize heavy-blocking
environments.
Prerequisites
A basic knowledge of locking concepts and transaction isolation level concepts
A basic understanding of how to use a profiler trace
Scenario
There are several applications that are based on the AdventureWorksdatabase. These
applications include online transaction processing (OLTP) type of applications, such as sales
order processing, and online analytical processing (OLAP) type applications, such as
statistical query. Recently, customers found that some queries are running slow, and the
development team reported that they see database 1205 errors in the application log.
Note that some of the problems might be related to stored procedures and triggers.
Objectives
In this exercise, you will:
Identify blocking by using dynamic management views (DMVs).
Identify blocking by using Extended Events.
Prerequisites
Connect to the SQLPTO virtual machine.
Signin by using the following credentials:
User name:SQLPTO\Administrator
Password:P@$$w0rd1
Note: The virtual machine for this workshop is time bombed for security purposes. You might need to
rearm the virtual machine if the activation expires. If you see a message to reactivate the virtual
machine, you can use the slmgr.vbs file with the rearm option as follows:
Scenario
Customers report that some queries are running slow and they suspect that the databases have
blocking issues. Now, you need to identify the reason for the blocking issues and identify the
queries that are responsible.
CASE WHEN er.session_idIS NULL
THEN es.session_id
ELSE er.session_id
er.blocking_session_id,
er.wait_time,
er.wait_resource,
er.wait_type,
er.last_wait_type,
er.status,
FROM sys.dm_exec_sql_text(ec.most_recent_sql_handle))
FROM sys.dm_exec_sql_text(er.sql_handle))
FROM sys.dm_exec_connectionsec
JOINsys.dm_exec_sessionses ON ec.session_id=es.session_id
LEFTJOINsys.dm_exec_requestser ON es.session_id=er.session_id
WHERE er.blocking_session_id> 0
ORes.session_idIN (SELECT blocking_session_id
FROM sys.dm_exec_requests
WHERE blocking_session_id> 0)
GO
RECONFIGURE
GO
6. Open and run the BlockedProcessReport.sqlfile to create and start an Extended Events
session that will collect the Blocked Process Report event in an in-memory ring buffer.
CREATE EVENT SESSION [BlockedProcessReport]ON SERVER
ADD EVENT sqlserver.blocked_process_report
ADD TARGET package0.ring_buffer(SET max_events_limit=(0),max_memory=(2048))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPAT
CH_LATENCY=30SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSAL
ITY=OFF,STARTUP_STATE=OFF)
GO
ON SERVER
STATE=START
GO
7. In the Management Studio Object Explorer, go to Management > Extended Events >
Sessions. If you do not see the BlockedProcessReportsession, right-click Sessions, and
click Refresh. After you see the BlockedProcessReportsession, right-click it and
click Watch Live Data.
8. Wait for some time to see if there is a blocking event captured in the ring buffer. After
you see an event, double-click the blocked_processrow in the bottom pane to view the
XML type of blocked process report.
Question