Condividi tramite


Identify and kill SQL processes causing CPU shortage

There might be cases in which the SQL processes running against the MSCRM database, start using all available CPU resources causing bad performance and downtimes. Using the following script it is easy to identify which processes are running in the SQL instance and, take reactive actions.

-- THIS SCRIPT HAS TO BE USED IN CASE THE SQL SERVER CPU REMAINS CONSTANTLY AT 100%

-- IT ALLOWS TO INTERCEPT (AND KILL IF NECESSARY) THE PROCESS CAUSING THE PROBLEM

-- CHANGE THE CONTEXT TO MASTER AND LIST ALL THE PROCESSES RUNNING

-- AGAINST THE CRM DATABASE SORTING BY CPU UTILIZATION.

-- REMEMBER TO CHANGE THE DATABASE NAME ACCORDING TO THE NAME OF THE CRM DATABASE

USE Master

GO

 

-- RETRIEVE THE DATABASE ID FOR THE MSCRM DATABASE

DECLARE @DATABASE_ID INT

SET @DATABASE_ID = DB_ID(N'OrganizationName_MSCRM');

 

SELECT ST.TEXT,

SP.*

FROM DBO.SYSPROCESSES SP

CROSS APPLY SYS.DM_EXEC_SQL_TEXT(SP.SQL_HANDLE) ST

WHERE SP.DBID = @DATABASE_ID

ORDER BY CPU DESC

GO

 

-- ONCE YOU IDENTIFY THE PROCESS, IF IS POSSIBLE, KILL IT. TO KILL THE PROCESS IDENTIFY ITS

-- SPID AND USE THE KILL COMMAND (REMEMBER TO REMOVE "<" AND ">")

KILL <SPID>

Carlo Gallazzi | Business Systems Architect | Microsoft Dynamics CRM

Comments

  • Anonymous
    May 07, 2009
    The comment has been removed