PROBLEM:
What should I do when SQL Server query is stuck?
SOLUTION:
First, open SQL Server Activity Monitor, you should wait some time before data is loaded
The Activity Monitor is available in SQL Server 2008 Management Studio is a great tool which can be used to get a quick overview of SQL Server 2008 system performance. The Activity Monitor tool in the previous version of SQL Server used to display information related to processes, lock by objects and locks by process. There are many enhancements in Activity Monitor in SQL Server 2008 like a graphical display of processor time, waiting tasks, database I/O's, batch requests, processes, resource waits, data file I/O's and also information about the most expensive queries.
To view Activity Monitor in SQL Server 2005 and in SQL Server 2008, a user must have VIEW SERVER STATE permission
One of the first lines of defense in determining why a query is stuck is to use sp_who2. It will shows all the sessions that are currently established in the database. These are denoted as SPID’s, or server process Id’s.
sp_who2
There are four main things to look for when when diagnosing slowdowns:
- Blocking
- High CPU usage
- High IO usage
- Multiple entries for the same SPID (representing parallelism)
DBCC INPUTBUFFER(500) -- 500 represent the SPID you see in the result of sp_who2
IMPORTANT: before the kill, keep a copy of the SQL statement being run for later investigation
KILL 500
sp_who2 does provide limited information regarding slowdowns.
For more information use the following script that shows the SQL statement being run, only sessions that have a current executing request, reads and writes for the current command, along with the number of reads and writes for the entire SPID and the protocol being used (TCP, NamedPipes, or Shared Memory)
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED SELECT SPID = er.session_id , BlkBy = er.blocking_session_id , ElapsedMS = er.total_elapsed_time , CPU = er.cpu_time , IOReads = er.logical_reads + er.reads , IOWrites = er.writes , Executions = ec.execution_count , CommandType = er.command , ObjectName = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid) , SQLStatement = SUBSTRING ( qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2 ELSE er.statement_end_offset END - er.statement_start_offset)/2 ) , Status = ses.status , [Login] = ses.login_name , HOST = ses.host_name , DBName = DB_Name(er.database_id) , LastWaitType = er.last_wait_type , StartTime = er.start_time , Protocol = con.net_transport , transaction_isolation = CASE ses.transaction_isolation_level WHEN 0 THEN 'Unspecified' WHEN 1 THEN 'Read Uncommitted' WHEN 2 THEN 'Read Committed' WHEN 3 THEN 'Repeatable' WHEN 4 THEN 'Serializable' WHEN 5 THEN 'Snapshot' END , ConnectionWrites = con.num_writes , ConnectionReads = con.num_reads , ClientAddress = con.client_net_address , Authentication = con.auth_scheme FROM sys.dm_exec_requests er LEFT JOIN sys.dm_exec_sessions ses ON ses.session_id = er.session_id LEFT JOIN sys.dm_exec_connections con ON con.session_id = ses.session_id CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt OUTER APPLY ( SELECT execution_count = MAX(cp.usecounts) FROM sys.dm_exec_cached_plans cp WHERE cp.plan_handle = er.plan_handle) ec ORDER BY er.blocking_session_id DESC, er.logical_reads + er.reads DESC, er.session_id
The following script will show the blocking processes (lead blocker)
SELECT spid , sp.status , loginame = SUBSTRING(loginame, 1, 12) , hostname = SUBSTRING(hostname, 1, 12) , blk = CONVERT(char(3), blocked) , open_tran , dbname = SUBSTRING(DB_NAME(sp.dbid),1,10) , cmd , waittype , waittime , last_batch , SQLStatement = SUBSTRING ( qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(MAX), qt.text)) * 2 ELSE er.statement_end_offset END - er.statement_start_offset)/2 ) FROM master.dbo.sysprocesses sp LEFT JOIN sys.dm_exec_requests er ON er.session_id = sp.spid OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt WHERE spid IN (SELECT blocked FROM master.dbo.sysprocesses) AND blocked = 0
The following script will find most expensive queries (remark the needed ORDER BY)
SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1, ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(qt.TEXT) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2)+1), qs.execution_count, qs.total_logical_reads, qs.last_logical_reads, qs.total_logical_writes, qs.last_logical_writes, qs.total_worker_time, qs.last_worker_time, qs.total_elapsed_time/1000000 total_elapsed_time_in_S, qs.last_elapsed_time/1000000 last_elapsed_time_in_S, qs.last_execution_time, qp.query_plan FROM sys.dm_exec_query_stats qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp ORDER BY qs.total_logical_reads DESC -- logical reads -- ORDER BY qs.total_logical_writes DESC -- logical writes -- ORDER BY qs.total_worker_time DESC -- CPU time
The following script will find longest running query
SELECT DISTINCT TOP 10 t.TEXT QueryName, s.execution_count AS ExecutionCount, s.max_elapsed_time AS MaxElapsedTime, ISNULL(s.total_elapsed_time / s.execution_count, 0) AS AvgElapsedTime, s.creation_time AS LogCreatedOn, ISNULL(s.execution_count / DATEDIFF(s, s.creation_time, GETDATE()), 0) AS FrequencyPerSec FROM sys.dm_exec_query_stats s CROSS APPLY sys.dm_exec_sql_text(s.sql_handle) t ORDER BY s.max_elapsed_time DESC
LETS CHECK, do the following steps and run the above scripts when needed
-- open new query window (SESSION A) and run the following 3 lines USE [AdventureWorks] BEGIN TRANSACTION UPDATE Sales.SalesOrderDetail SET [UnitPrice] = 1 -- this update takes ~30sec -- while the above update in progress, open a new query window (SESSION B) and run sp_who2 -- open another query window (SESSION C) and run the following line, it will be blocked by SESSION A because the transaction there is not committed yet UPDATE Sales.SalesOrderDetail SET [UnitPrice] = 2 -- while the above update in progress, go to SESSION B query window and run again sp_who2, you will see the blocking -- return to SESSION A query window and rollback the transaction. This will free the blocking in SESSION C (after the update finishes, takes ~30sec) ROLLBACK
If you find this solution useful, you are welcome to press one of the ads in this page.. Thanks!
When click on the Activity Monitor, I receive this error message: "This operation does not support connections to the Sql Azure Database.."
ReplyDeleteExcellent! Thank you for this post - got me unstuck.
ReplyDeleteI want to thank you for this blog post. It was extremely helpful in solving a major problem plus it gave me another tool to put in my toolkit.
ReplyDeleteexcellent post thank you i think this blog very useful who have that type of problem Sql Server dba Online Training Bangalore
ReplyDeleteSolve your Simple MS SQL Bugs with Microsoft SQL Server Support
ReplyDeleteActually this is happens with mostly new MS SQL Server users, when they trying to get all duplicates emails in a table, suddenly they got an error message “Error invalid Column Name CT”, and due to the lack of technical skill they do not how to overcome of this problem. But don’t worry we help you by providing most appropriate solution i.e. Remote Infrastructure Management Support for Microsoft SQL Server or Online MS SQL Server Support. Do not waste your time in searching for other support just dial this number 1-800-450-8670 and get most trusted support through SQL Server Database Support.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801
Investigate MS SQL Server 2008 Connection Issue by means of Online MS SQL Server Support
ReplyDeleteOrdinarily clients griping that they need to confront SQL Server 2008 association issue. To take care of this issue they are attempting to MySQL ODBC connector to associate with MS SQL Server yet in the meantime the association’s bombs inevitably. Ensure in the event that you are new client or don't know how to explain this issue, at that point without squandering your an excessive amount of time contact to Remote Infrastructure Management Support for Microsoft SQL Server or Microsoft SQL Server Support for best arrangement through committed and experienced specialists.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801
Get Fast MS SQL Server Connection Help with Online MS SQL Server Support
ReplyDeleteIn the event that any of the client who utilize MS SQL Server for their work and if standing up to any issue or have some question in regards to this at that point connect with Remote Infrastructure Management Support for Microsoft SQL Server or Microsoft SQL Server Support. With the commitment of most skilled and experienced experts we encourage the best help to our clients. In the event that any kind of issue you may experience at that point contact to our SQL Server Database Support.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801
Step by step instructions to Solve MS SQL Server 2005 Login Issue through Online MS SQL Server Support
ReplyDeleteOn the off chance that any client as of now introduce MS SQL Server 2005 on their workstation or framework, on the off chance that he runs an overseer then he can sign in however when he attempt straightforwardly to login then he get a blunder code which demonstrates Error 18456 at that point by what method will you tackle this issue? On the off chance that any clients who confronting that sort of issue than basically contact to Remote Infrastructure Management Support for Microsoft SQL Server or Microsoft SQL Server Support. In the event that you feel powerless and not ready to take care of this issue then SQL Server Database Support is the most ideal approach to tackle this issue.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801
ReplyDeleteThanks for sharing Good Information
Sql server DBA Online Course
How to Solve MS SQL Server Hostname Connectivity Issue? Contact to Microsoft SQL Server Support
ReplyDeleteIn some of the cases the MS SQL Server hostname connectivity issue occurs due to if string too long or string malformed. To tackle this problem chooses Cognegic’s Remote Infrastructure Management Support for Microsoft SQL Server or Online MS SQL Server Support. We are able to diagnose existing performance problem and also improved database performance and resource management. Our all technical experts are capable to configure, optimize and analyze storage engines.
For More Info: https://cognegicsystems.com/
Contact Number: 1-800-450-8670
Email Address- info@cognegicsystems.com
Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801
Just thought I'd let you know this solved an issue for us today in 2018. Thanks for the write up!
ReplyDeleteVery nice article!
ReplyDeleteThanks.
Ravi (DotNetTec)
Eskişehir
ReplyDeleteAdana
Sivas
Kayseri
Samsun
Q584Y
Balıkesir
ReplyDeleteBursa
Mersin
Konya
Van
3AHL
görüntülü show
ReplyDeleteücretlishow
D7NJZM
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
X7VCG
hatay evden eve nakliyat
ReplyDeleteısparta evden eve nakliyat
erzincan evden eve nakliyat
muğla evden eve nakliyat
karaman evden eve nakliyat
HXP1OK
tekirdağ evden eve nakliyat
ReplyDeletekocaeli evden eve nakliyat
yozgat evden eve nakliyat
osmaniye evden eve nakliyat
amasya evden eve nakliyat
R1XL3
678CE
ReplyDeleteHatay Şehirler Arası Nakliyat
Çerkezköy Çelik Kapı
Rize Şehir İçi Nakliyat
Hakkari Parça Eşya Taşıma
Amasya Şehir İçi Nakliyat
Ardahan Şehir İçi Nakliyat
Gate io Güvenilir mi
Mardin Lojistik
Artvin Şehir İçi Nakliyat
FB5E1
ReplyDeleteAksaray Şehirler Arası Nakliyat
Kayseri Lojistik
Isparta Şehir İçi Nakliyat
Kastamonu Lojistik
Bitlis Şehir İçi Nakliyat
Ünye Asma Tavan
Diyarbakır Lojistik
Artvin Parça Eşya Taşıma
Bilecik Şehir İçi Nakliyat
54BE3
ReplyDeleteElazığ Parça Eşya Taşıma
Altındağ Fayans Ustası
Afyon Parça Eşya Taşıma
Iğdır Parça Eşya Taşıma
Çanakkale Şehirler Arası Nakliyat
Van Şehir İçi Nakliyat
Ardahan Parça Eşya Taşıma
Çorum Şehirler Arası Nakliyat
Uşak Şehir İçi Nakliyat
6D3F7
ReplyDeletehttps://referanskodunedir.com.tr/
8D00B
ReplyDeleteburdur telefonda sohbet
kadınlarla sohbet
mardin rastgele görüntülü sohbet ücretsiz
rastgele sohbet odaları
tekirdağ canli goruntulu sohbet siteleri
hatay sohbet sitesi
yabancı canlı sohbet
bayburt ücretsiz sohbet odaları
ağrı kadınlarla sohbet et
E7340
ReplyDeleteKarabük Kızlarla Canlı Sohbet
Denizli Ücretsiz Görüntülü Sohbet
ankara canlı sohbet
telefonda kızlarla sohbet
rastgele canlı sohbet
urfa sesli görüntülü sohbet
hatay ucretsiz sohbet
osmaniye yabancı görüntülü sohbet
Aksaray Telefonda Görüntülü Sohbet
800E4
ReplyDeletekars telefonda kadınlarla sohbet
van bedava görüntülü sohbet sitesi
şırnak sohbet uygulamaları
samsun kadınlarla sohbet et
Aksaray Kadınlarla Rastgele Sohbet
samsun mobil sohbet odaları
Tokat Görüntülü Sohbet Siteleri Ücretsiz
amasya mobil sohbet siteleri
Uşak Canli Goruntulu Sohbet Siteleri
F33D6
ReplyDeleteNonolive Takipçi Satın Al
Coin Üretme
Likee App Takipçi Satın Al
Youtube Beğeni Satın Al
Parasız Görüntülü Sohbet
Snapchat Takipçi Hilesi
Kwai Beğeni Hilesi
Bitcoin Nasıl Alınır
Qlc Coin Hangi Borsada
THGNYTFGJ
ReplyDeleteتسليك مجاري بالهفوف
شركة عزل خزانات rtcWnj8uqN
ReplyDeleteشركة عزل اسطح بالاحساء 5ISC0Izsy4
ReplyDeleteشركة تنظيف مجالس بالدمام qmyFxCTpWE
ReplyDeletehttps://elrokn-elmethaly.com/%d8%b4%d8%b1%d9%83%d8%a9-%d9%84%d8%ad%d8%a7%d9%85-%d9%88%d8%b5%d9%8a%d8%a7%d9%86%d8%a9-%d8%ae%d8%b2%d8%a7%d9%86%d8%a7%d8%aa-%d8%a8%d8%a8%d8%b1%d9%8a%d8%af%d8%a9/ CmZjnhZtAm
ReplyDeleteشركة تسليك مجاري بالقطيف Xd6BDLsIQJ
ReplyDeleteشركة تنظيف مجالس بالدمام ObfXzTGB91
ReplyDeleteشركة عزل اسطح بالمدينة المنورة XS8wUuhQAW
ReplyDeleteE8450B7F21
ReplyDeletetwitter takipçi satın al