Checking percentage completion of backup or restore tasks in SQL 2000 and earlier versions are required to use monitoring option BACKUP DATABASE ... WITH STATS [= percentage]. But in SQL 2005 and later versions one of the dynamic management views (DMVs) sys.dm_exec_requests can be used to check the percentage of completion of a task, not only backup and restore, this dmv helps to troubleshoot performance issues as well but here I’m writing only how to ensure how much percentage completed a specific task.
I’ve used the below query to check how much percentage the database backup completed also calculated the estimated and elapsed time in minutes. The default value for estimated_completion_time and total_elapsed_time are in milliseconds.
SQL Statement
SELECT percent_complete , (estimated_completion_time/1000)/60 Estimated_completion_time_Mins ,(total_elapsed_time/1000)/60 Total_Elapsed_Time_Mins ,DB_NAME(Database_id) DBName ,*FROMsys.dm_exec_requests WHERE session_id=3576
The above example query result set is below, BACKUP DATABASE has been completed 66.56% and the current estimatated completion time is 6 mins (actual value is in milliseconds) from now and Total elapsed time is 12mins .
The above SQL statements can be used to check the percentage completion for the following tasks as well.
1. BACKUP and RESTORE
2. DBCC CHECKDB and CHECKTABLE
3. DBCC SHRINKDB and SHRINKFILES
4. DBCC INDEXDEFRAG
5. ALTER INDEX REORGANIZE
6. ROLLBACK
I’ve used the below query to check how much percentage the database backup completed also calculated the estimated and elapsed time in minutes. The default value for estimated_completion_time and total_elapsed_time are in milliseconds.
SQL Statement
SELECT percent_complete , (estimated_completion_time/1000)/60 Estimated_completion_time_Mins ,(total_elapsed_time/1000)/60 Total_Elapsed_Time_Mins ,DB_NAME(Database_id) DBName ,*FROMsys.dm_exec_requests WHERE session_id=3576
The above example query result set is below, BACKUP DATABASE has been completed 66.56% and the current estimatated completion time is 6 mins (actual value is in milliseconds) from now and Total elapsed time is 12mins .
The above SQL statements can be used to check the percentage completion for the following tasks as well.
1. BACKUP and RESTORE
2. DBCC CHECKDB and CHECKTABLE
3. DBCC SHRINKDB and SHRINKFILES
4. DBCC INDEXDEFRAG
5. ALTER INDEX REORGANIZE
6. ROLLBACK