Troubleshooting SQL Server Session

Source: Internet
Author: User
Tags session id

--Find session ID by job name

Select A.spid,a.blocked,b.name,substring (replace (a.program_name, ' Sqlagent-tsql JobStep (Job ', '), 1,34) JobStep, A.last_batch
From master.dbo.sysprocesses a INNER join Msdb.dbo.sysjobs b
On MASTER.DBO.FN_VARBINTOHEXSTR (CONVERT (varbinary), job_id) = substring (replace (program_name, ' Sqlagent-tsql JobStep (Job ', '), 1,34)

--execution plan based on session ID

Select A1.session_id,b1.text,a1.query_plan,a1.cpu_time,a1.logical_reads,a1.sql_handle,a1.plan_handle from
(
SELECT * from sys.dm_exec_requests a cross apply sys.dm_exec_query_plan (A.plan_handle) b
where a.session_id<>@ @spid
) A1 cross apply sys.dm_exec_sql_text (A1.sql_handle) B1
ORDER BY a1.cpu_time Desc

--View Execution plan
SET STATISTICS IO on
Set STATISTICS TIME on
Set STATISTICS PROFILE on

--A single statement executes quickly, but the session is not over for a long time

Determines whether the statement loops Execution (view SP content), executes the same statement multiple times,

Causes the surface to be simple SQL, but repeated execution of the same statement, that is, a statement running slowly resulting in the session execution for a long time, in fact, nx a single time

Troubleshooting SQL Server Session

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.