In the Part 1, we have seen how quickly we can check the runnable task and I/O pending task on an SQL server instance. This is very light weight script and it will give the result even if the server is under pressure and will give an over all state of the server at that moment.
The next step (Step2) in my way of diagnosing is to check the session that are waiting of any resources. Below script will help us. This query required a function as prerequisite, which will help us to display the SQL server agent job name if the session started by SQL server agent.
/*****************************************************************************************
PREREQUISITE FUNCTION
******************************************************************************************/
USE MASTER
GO
CREATE FUNCTION ConvertStringToBinary ( @hexstring VARCHAR(100)
) RETURNS BINARY(34) AS
BEGIN
RETURN(SELECT CAST('' AS XML).value('xs:hexBinary( substring(sql:variable("@hexstring"), sql:column("t.pos")) )', 'varbinary(max)')
FROM (SELECT CASE SUBSTRING(@hexstring, 1, 2) WHEN '0x' THEN 3 ELSE 0 END) AS t(pos))
END
/***************************************************************************************
STEP 2: List the session which are currently waiting for resource
****************************************************************************************/
SELECT node.parent_node_id AS Node_id,
es.HOST_NAME,
es.Login_name,
CASE WHEN es.program_name LIKE '%SQLAgent - TSQL JobStep%' THEN
(
SELECT 'SQL AGENT JOB: '+name FROM msdb..sysjobs WHERE job_id=
MASTER.DBO.ConvertStringToBinary (LTRIM(RTRIM((SUBSTRING(es.program_name,CHARINDEX('(job',es.program_name,0)+4,35)))))
)
ELSE es.program_name END AS [Program Name] ,
DB_NAME(er.database_id) AS DatabaseName,
er.session_id,
wt.blocking_session_id,
wt.wait_duration_ms,
wt.wait_type,
wt.NoThread ,
er.command,
er.status,
er.wait_resource,
er.open_transaction_count,
er.cpu_time,
er.total_elapsed_time AS ElapsedTime_ms,
er.percent_complete ,
er.reads,
er.writes,
er.logical_reads,
wlgrp.name AS ResoursePool ,
SUBSTRING (sqltxt.TEXT,(er.statement_start_offset/2) + 1,
((CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), sqltxt.TEXT)) * 2
ELSE er.statement_end_offset
END - er.statement_start_offset)/2) + 1) AS [Individual Query],
sqltxt.TEXT AS [Batch Query]
FROM (SELECT session_id, SUM(wait_duration_ms) AS
wait_duration_ms,wait_type,blocking_session_id,COUNT(*) AS NoThread
FROM SYS.DM_OS_WAITING_TASKS GROUP BY session_id, wait_type,blocking_session_id) wt
INNER JOIN SYS.DM_EXEC_REQUESTS er ON wt.session_id=er.session_id INNER JOIN SYS.DM_EXEC_SESSIONS es ON es.session_id= er.session_id
INNER JOIN SYS.DM_RESOURCE_GOVERNOR_WORKLOAD_GROUPS wlgrp ON wlgrp.group_id=er.group_id
INNER JOIN (SELECT os.parent_node_id ,task_address FROM SYS.DM_OS_SCHEDULERS OS INNER JOIN
SYS.DM_OS_WORKERS OSW ON OS.scheduler_address=OSW.scheduler_address
WHERE os.status='VISIBLE ONLINE' GROUP BY os.parent_node_id ,task_address ) node
ON node.task_address=er.task_address
CROSS APPLY SYS.DM_EXEC_SQL_TEXT(er.sql_handle) AS sqltxt
WHERE sql_handle IS NOT NULL AND wt.wait_type NOT IN ('WAITFOR','BROKER_RECEIVE_WAITFOR')
GO
The Description of the columns in the result are given below.
Column Name | Description |
Node Id | NUMA node id . Can be mapped to the node id of the scheduler query. |
Host_Name | Name of the computer from the connection is originated. |
Login Name | Login used in the session to connect the database server |
Program Name | Name of the program/application using this session. You can set the application name in the connection string. If this session is part of SQL server agent job, it will show the job name |
Database Name | Current database of the session |
Session Id | The session id |
Blocking Session id | Session id blocking statement |
wait_duration_ms | Total wait time for this wait type, in milliseconds. This time is inclusive of signal wait time |
wait_type | Name of the wait type like SLEEP_TASK,CXPACKET etc |
No of Thread | No of threads running on this session. If the session is in parallel execution |
Command | Identifies the current type of command that is being processed like Select,insert,update,delete etc |
Status | Status of the request. This can be of the following: Background,Running,Runnable,Sleeping and Suspended |
Wait Resource | Resource for which the request is currently waiting |
Open Transaction count | Number of transaction opened in this session |
Cpu Time | CPU time in milliseconds that is used by the request. |
Total Elapsed Time | Total time elapsed in milliseconds since the request arrived |
Percent_Complete | Percent of work completed for certain operations like backup,restore rollback etc. |
Reads | Number of reads performed by this request. |
Writes | Number of writes performed by this request. |
logical_reads | Number of logical reads performed by this request. |
ResoursePool | Name of of Resource Governor Pool |
Individual Query | current statement of the batch running on this session. |
Batch Query | Current batch (procedure/set of sql statement) running on this session. |
If there is a session with very long wait_duration_ms and not blocked by any other session and not going away from the list in the subsequent execution of the same query, I will look into the program name,host name,login name and the statement that is running which will give me an idea about the session.Based on all these information, I might decide to kill that session and look into the implementation of that SQL batch. If the session is blocked, I will look into the blocking session using a different script which I will share later.(Refer this post)
The next step (Step 3) is to list all session which are currently running on the server. I use below query to do that.
/***************************************************************************************
/***************************************************************************************
STEP 3: List the session which are currently waiting/running
****************************************************************************************/SELECT node.parent_node_id AS Node_id,
es.HOST_NAME,
es.login_name,
CASE WHEN es.program_name LIKE '%SQLAgent - TSQL JobStep%' THEN
(SELECT 'SQL AGENT JOB: '+name FROM msdb..sysjobs WHERE job_id=ADMIN.DBO.ConvertStringToBinary (LTRIM(RTRIM((SUBSTRING(es.program_name,CHARINDEX('(job',es.program_name,0)+4,35)))))
)ELSE es.program_name END AS program_name ,
DB_NAME(er.database_id) AS DatabaseName,
er.session_id,
wt.blocking_session_id,
wt.wait_duration_ms,
wt.wait_type,
wt.NoThread ,
er.command,
er.status,
er.wait_resource,
er.open_transaction_count,
er.cpu_time,
er.total_elapsed_time AS ElapsedTime_ms,
er.percent_complete ,
er.reads,er.writes,er.logical_reads,
wlgrp.name AS ResoursePool ,
SUBSTRING (sqltxt.TEXT,(er.statement_start_offset/2) + 1,
((CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), sqltxt.TEXT)) * 2
ELSE er.statement_end_offset
END - er.statement_start_offset)/2) + 1) AS [Individual Query],
sqltxt.TEXT AS [Batch Query]
FROM
SYS.DM_EXEC_REQUESTS er INNER JOIN SYS.DM_EXEC_SESSIONS es ON es.session_id= er.session_id
INNER JOIN SYS.DM_RESOURCE_GOVERNOR_WORKLOAD_GROUPS wlgrp ON wlgrp.group_id=er.group_id
INNER JOIN (SELECT os.parent_node_id ,task_address FROM SYS.DM_OS_SCHEDULERS OS
INNER JOIN SYS.DM_OS_WORKERS OSW ON OS.scheduler_address=OSW.scheduler_address
WHERE os.status='VISIBLE ONLINE' GROUP BY os.parent_node_id ,task_address ) node ON node.task_address=er.task_address
LEFT JOIN
(SELECT session_id, SUM(wait_duration_ms) AS
wait_duration_ms,wait_type,blocking_session_id,COUNT(*) AS NoThread
FROM SYS.DM_OS_WAITING_TASKS GROUP BY session_id, wait_type,blocking_session_id) wt
ON wt.session_id=er.session_id
CROSS apply SYS.DM_EXEC_SQL_TEXT(er.sql_handle) AS sqltxt
WHERE sql_handle IS NOT NULL AND ISNULL(wt.wait_type ,'') NOT IN
('WAITFOR','BROKER_RECEIVE_WAITFOR')
ORDER BY er.total_elapsed_time DESC
GO
The columns are same as we discussed in step 2 . I used to analyse the sessions with more total_elapsed_time and take appropriate actions like killing the session and look into the implementation. In most of the scenario (where server was running perfectly but all off sudden it become standstill) , I will be able fix the issue by following these steps. In the next part let us discuss about blocking session and session with open transaction which is not active.If you liked this post, do like my page on FaceBook
Nice article. What's the different between step 2 and step 3? The queries look the same with minor difference.
ReplyDeleteTry using minidba from www.minidba.com to make the most of sql server dmvs without having to roll your own code. #hugetimesaving
ReplyDeletethank you!
ReplyDelete
ReplyDeleteI loved the way you discuss the topic great work thanks for the share, Let me share this, Hadoop training in pune
Nice article, Thanks for sharing and keep sharing.
ReplyDeleteerp software in chennai | erp providers in chennai | online events registration
Thank you for your nice post. It is really useful. cashew nuts supplier in india | cashew nuts supplier in dubai
ReplyDeleteI want to say that all the information you have given In this post is awesome. Great and nice blog thanks for sharing you Knowledge.
ReplyDeleteOracle Fusion Financials Training
Interesting post! This is really helpful for me. I like it! Thanks for sharing!
ReplyDeleteseo lüdenscheid
سماك هو برنامج محاسبة عبر الإنترنت للشركات الصغيرة والمتوسطة لإدارة أعمالهم وزيادة الإنتاجية. لدى سماك خمس
ReplyDeleteوحدات رئيسية لإدارة العمليات التجارية لأي مؤسسة. وقد استفادت برامج محاسبة من سماك العديد من المؤسسات الصغيرة
والمتوسطة، وتحديدا الشركات الناشئة عن طريق خفض التكاليف السنوية والسماح لهم بالتركيز الكامل على تطوير الأعمال الأساسية وعمليات الأعمال بدلا من أنها عثرت في مشاكل البنية التحتية لتكنولوجيا المعلومات
والقضايا.
ومن الفوائد الرئيسية الأخرى برامج محاسبة السحابية من سماك أن الترقيات مجانية تماما ومتكررة وفورية ولكن من ناحية
أخرى فإن دورات تطوير البرمجيات داخل المؤسسة طويلة جدا بالمقارنة مع برمجيات المحاسبة المستندة إلى الحوسبة السحابية.
تحميل برامج المحاسبة
افضل برنامج محاسبة
برامج محاسبة
برنامج محاسبة
نظام نقاط البيع
محاسبة مالية
سماك
tutu app
ReplyDeletetutu app download
tutu app free
tutuapp vip
TuTu App is an emerging popular app store alternative available on both platforms, iOS and Android.
مخاطر الحشرات كثيرة ولو تريد حل قوي وفعال في التخلص من الحشرات في منزلك ليس امامك افضل من شركة مكافحة حشرات بجدة وفي حاجة إلى شركة رائدة تخلصك من الحشرات المنتشرة حولك فأليك الأن أقوى شركات منطقة جدة ومكة والطائف شركة مكافحة حشرات بجدة وكذلك في مكة المكرمة لدينا شركة مكافحة حشرات بمكة المكرمة ولدينا شركة رش مبيدات بالطائف متخصصة و شركة مكافحة حشرات بالطائف تعمل على مكافحة الحشرات المختلفة في المنازل والمزارع والحدائق والشوارع والفلل والقصور وغيرها من الأماكن المختلفة حيث توفر لك الخدمات اللازمة في حل مشاكلك الصعبة المتعلقة بالحشرات المنزلية.
ReplyDeleteتنظيف المنازل والبيوت من المهام الصعبة على ربات البيوت ونحن نقدم لكم تلك الخدمات
ReplyDeleteشركة تنظيف منازل بجدة
شركة تنظيف منازل بمكة
افضل شركة تنظيف بجدة
شركة تنظيف منازل
Thank you for this wonderful and useful article
ReplyDeleteشركة مكافحة حشرات بخميس مشيط
شركة مكافحة حشرات بالقصيم
شركة مكافحة حشرات بأبها
شركة مكافحة حشرات بنجران
شركة مكافحة حشرات بجازان
شركة مكافحة حشرات ببريدة
شركة مكافحة حشرات بالطائف
https://5c865c48ee083.site123.me/
ReplyDeletehttp://publish.lycos.com/acmarketapk/2019/03/11/blackmart-apk/
https://blackmart-apk.sitey.me/
https://blackmartapk.zohosites.in/
https://blackmartapk.pb.online/
http://blurpalicious.com/p/blackmart-apk/
shareit apk
ReplyDeleteshareit downloading
shareit apk downloading
http://gmail-gmail.com/the-way-to-unroot-an-android-machine/
ReplyDeletehttp://www.nikeairhuarachenm.com/tips-on-how-to-take-away-a-virus-from-my-android-telephone/
http://www.statue-et-compagnie.com/android-four-zero-what-you-must-know/
http://www.bilbaohotelsstay.com/amazon-immediate-on-android/
http://www.azeerentaldubai.com/what-to-do-to-get-the-most-from-the-google-play-retailer/
blackmart apk
ReplyDeletegbwhatsapp apk
ac market
live nettv apk
happy chick apk
Blackmart alpha apk
dj liker apk
video downloader apk
TeaTV apk
Thank you so much for the information which is great and very good post.
ReplyDeletehttp://rajithap3.angelfire.com/
https://www.diigo.com/item/note/6vsf0/1abt?k=d5992b2f1e2b33a4e30fa3e2b72da141
http://acmarket3.bravesites.com/#builder
http://acmarketapk.greatwebsitebuilder.com/
https://peddi-rajitha.jimdosite.com/
http://acmarket3.emyspot.com/
http://acmarketapk3.sosblog.com/admin.php?ctrl=posts&tab=posts&blog=1
https://saimallikarjuan-raju.jimdosite.com/
https://sites.google.com/view/livenettvapk9515/home
I found such amazing information on this blog. Visit Thecorporategift for Promotional Products and Corporate Diwali Gift.
ReplyDeletePromotional Products
download nintendo 3ds emulator for pc
ReplyDeletedownload nintendo 3ds emulator on windows pc
nintendo 3ds emulator pc
Visit Thecorporategift for Promotional Products and Corporate Diwali Gift.
Nice blog, keep it up for more updates. Visit Sarswati Enterprises for Flip off Seals Machinery and ROPP Caps Making Machinery Manufacturer in Delhi, India.
ReplyDeleteROPP Caps Making Machinery
Amazing blog, thanks for sharing with us. Book Shimla Manali Tour Package from Delhi at best price.
ReplyDeleteShimla Manali Tour Package from Delhi
Nice blog, thank you so much for sharing this. Get Noble IVF wide array of services with advance facility and well experienced fertility doctors.
ReplyDeleteIVF Centre in Aligarh
I never comment on blogs but your article is so best that I never stop myself to say something about it. You’re amazing Man, I like it WP-Database Issues ... Keep it up
ReplyDeleteTS Eamcet 2020 Exam Notification
ReplyDeleteTS Eamcet 2020 Exam Date
TS Eamcet 2020 Apply online
TS Eamcet 2020 Syllabus
TS Eamcet 2020 Exam fee
Get Noble IVF wide array of services with advance facility and well experienced...
hotmail.com signup
ReplyDeletefull information with FAQs are given.......
Amazing! This article is jam-pressed brimming with helpful data. The focuses made here are clear, succinct, meaningful, and powerful. I actually like your composing style.
ReplyDeleteSEO services in kolkata
Best SEO services in kolkata
SEO company in kolkata
Best SEO company in kolkata
Top SEO company in kolkata
Top SEO services in kolkata
SEO services in India
SEO copmany in India
I might want to remark on this quality substance. I can see you have done a great deal of schoolwork and really thought about this subject.
ReplyDeleteOnline Teaching Platforms
Online Live Class Platform
Online Classroom Platforms
Online Training Platforms
Online Class Software
Virtual Classroom Software
Online Classroom Software
Learning Management System
Learning Management System for Schools
Learning Management System for Colleges
Learning Management System for Universities
Identify which of the clients being mentioned as references are actually referencable Salesforce training in Hyderabad
ReplyDeleteIt's fantastic that you are getting ideas from this post as well as from our discussion made here.I have enjoyed reading your articles. It is well written. It looks like you spend a large amount of time and effort in writing the blog. I am appreciating your effort.Augurs GmbH
ReplyDeleteمدونة ممتازة ، لقد أحببتها كثيرًا لدرجة أنني عدت إلى هنا لتقديم ملاحظات. شكرا على كل حال.
ReplyDeleteتحقق أيضًا من COC MOD Apk
Thanks for the solution. It helped me a lot. Download FMWhatsApp APK
ReplyDeleteThank you for the detailed article on Database Server Performance Issues. I appreciate it. Download COC Mod APK
ReplyDeleteI am very impressed with your post, thanks for sharing. Keep sharing stuff like this in future. Regards COC MOD Apk.
ReplyDeleteI want to say that all the information you have given In this post is awesome. Great and nice blog thanks for sharing you Knowledge.
ReplyDeleteThis was very helpful in my school project, Thanks for sharing this with me. GBWhatsapp 2022 APK
ReplyDeleteIt's definitely the most important blog for me right now. You have shared very helpful blog on SQL that i was having issue with. Thanks a lot. fmwhatsapp
ReplyDeleteCSS Founder Pvt. Ltd. is known as the best website designing company in Ghaziabad. You can visit our website so that you can get a uniqe and cost-effective website from us. We are located in Dubai, you can visit here any time.
ReplyDeleteWe Carry More Than Just Good Coding Skills
ReplyDeleteSolutions that exceed your expectations with Phenix System
Perfect Solution for your business!
Phenix offers the ability to monitor your business wherever you are, with powerful mobile applications
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteفينيكس
ReplyDeleteيدعم فينيكس امكانية طباعة وقراءة الباركود البسيط ,والمدمج الذي يضم مجموعة من مواصفات المادة, كما يدعم امكانية تعدد الباركود على مستوى المادة وواحدات المادة
Thank you for sharing this useful blog. I like it.
ReplyDeletehttps://techupnew.com/ffh4x-injector/ you can check out my new blog
Thanks for sharing valuable and informative piece of content.
ReplyDeleteSoftware testing Training Course in Ghaziabad
Buen artículo, espero que escribas más artículos. También quiero presentarles la página https://apktodo.net/es/ para que se diviertan.
ReplyDeleteGreat insights on SQL Server! I've found similar challenges managing database servers. By the way, have you explored any Mod apk modsusu tools for database management? They can be quite handy!
ReplyDeleteGreat article! Regular backups and index maintenance are essential to prevent issues down the line. best seo services in gwalior
ReplyDeleteMakasih udah share artikel ini, sangat membantu untuk memahami pendekatan ke server database. Btw, ngomong-ngomong soal Mod apk apktodo, ada saran app buat cek performa database?
ReplyDeleteFantastic job on this post! Your engaging and straightforward approach made it very accessible. Looking forward to more great content from you! Luxury Property in gwalior
ReplyDelete