Monitoring the progress of an SQL query in SQL SERVER

∥☆過路亽.° 提交于 2019-11-29 05:36:22
KM.

There is no way to know how much time is left. A query's runtime depends on many things beyond the actual query itself: locking/blocking of other queries, other processes consuming resources (CPU/disk usage), the operating system, network, etc. What if your 5-minute query is running, yet someone else kicks off a large report, your query may run 5:30 now. What if the someone starts to download a large file and hogs all the network bandwidth? What if the OS decides to do something in the background, etc. Until all the rows are returned, the query isn't done, but it can run in a variable time frame.

What you want are Live Query Statistics.

You can activate it in the most recent version of SSMS with a button next to the one that gives you the normal query plan:

This then gives you a live query plan:

At the bottom you see the total progress:

Andrey.ca

sys.dm_exec_requests has that info, so something like that will give you the progress:

SELECT 
percent_complete
FROM sys.dm_exec_requests
--where session_id=51 or command like 'restore%'
JameSQL

Yes you can know the estimated elapsed time unless there would be some unexpected situation affecting the execution of the process.

Select total_elapsed_time,
 * from sys.dm_exec_sessions where session_id="your Id here" 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!