我们今天能为您提供什么帮助?

SQL Scripts to find all the Blocked Process/Query in a Power Monitoring Expert Database

Issue
When SQL Server is servicing requests from many clients, there is a strong possibility that conflicts will occur because different processes
request access to the same resources at the same time. A conflict in which one process is waiting for another to release a resource is called a block.
Although in SQL Server a blocked process usually resolves itself when the first process releases the resource, there are times when a process
holds a transaction lock and doesn't release it.

Product Line
ION EEM
ION Enterprise 6.0. x

Struxureware Power Monitoring 7.0.x
Power Monitoring Expert 7.2.2
Power Monitoring Expert 8.2
Power Monitoring Expert 9.0
Power Monitoring Expert 2020
Power Monitoring Expert 2021
Power Monitoring Expert 2022
Power Monitoring Expert 2023
Power Monitoring Expert 2024


Environment
SQL Server 2005

SQL Server 2008 R 2

SQL Server 2012

SQL Server 2014

SQL Server 2016

SQL Server 2017

SQL Server 2018

SQL Server 2019

Cause
Blocking occurs when one or more sessions request a lock on a resource, such as a row, page or table, but SQL Server cannot grant that lock because
another session already holds a non-compatible lock on that resource.

Resolution
*Warning: Irreparable database damage can occur. This procedure should only be performed by users familiar with SQL Server Management Studio. Databases should be backed up prior to performing this procedure.*

In order to resolve a blocked process, we first need to determine which process is the blocking process and then if possible kill the blocking process.


To determine which process is the blocking process log into SQL Server Management Studio and run the attached SQL script (Blocked_Process.sql).
Alternatively, execute the query(s) below :

Script to find all blocked processes:

SELECT
spid,
status,
loginame=SUBSTRING(loginame,1,12),
hostname=SUBSTRING(hostname,1, 12),
blk = CONVERT(char(3), blocked),
dbname=SUBSTRING(DB_NAME(dbid),1, 10),
cmd,
waittype
FROM master.dbo.sysprocesses
WHERE spid IN (SELECT blocked FROM master.dbo.sysprocesses)


Script to identify the blocking query:

SELECT
db.name DBName,
tl.request_session_id,
wt.blocking_session_id,
OBJECT_NAME(p.OBJECT_ID) BlockedObjectName,
tl.resource_type,
h1.TEXT AS RequestingText,
h2.TEXT AS BlockingTest,
tl.request_mode
FROM sys.dm_tran_locks AS tl
INNER JOIN sys.databases db ON db.database_id = tl.resource_database_id
INNER JOIN sys.dm_os_waiting_tasks AS wt ON tl.lock_owner_address =wt.resource_address
INNER JOIN sys.partitions AS p ON p.hobt_id =tl.resource_associated_entity_id
INNER JOIN sys.dm_exec_connections ec1 ON ec1.session_id =tl.request_session_id
INNER JOIN sys.dm_exec_connections ec2 ON ec2.session_id =wt.blocking_session_id
CROSS APPLY sys.dm_exec_sql_text(ec1.most_recent_sql_handle) AS h1
CROSS APPLY sys.dm_exec_sql_text(ec2.most_recent_sql_handle) AS h2
GO


Script to view all current processes / sessions on the server:

select * from master.dbo.sysprocesses

To kill a process use the task manager to "End Task" on the process relative to the SQL script output

  • to open the task manager you can use CTRL+SHIFT+ESC

施耐德電機Taiwan

附件
Blocked_Process.sql [325 Bytes]
Blocking_Query.sql [826 Bytes]
Current_Processes_Sessions.sql [105 Bytes]
探索更多
系列:
探索更多
系列:

需要協助?

需要協助?

產品選型工具

產品選型工具

快速輕鬆地為您的應用找到合適的產品和附件。

取得報價

取得報價

立即線上提交您的銷售需求,專業團隊將主動聯繫您。

購買地點

購買地點

輕鬆在您所在地區找到最近的施耐德電機經銷商。

支援中心

支援中心

在同一位置找到滿足您所有需求的支援資源。

  • 產品文檔
  • 軟體下載
  • 產品選型工具
  • 產品替代和替換
  • 幫助和聯絡中心
  • 尋找我們的辦公室
  • 取得報價
  • 施耐德電機社群
  • 人才招募
  • 公司簡介
  • 舉報不當行為
  • 無障礙
  • 新聞中心
  • 投資者
  • 專業洞察
  • 台灣施耐德電機學院
  • 綠色影響力落差調查
  • Schneider Go Green 2025
  • 隱私政策
  • Cookie通告
  • 使用條款
  • Change your cookie settings