Shrink, use sparsely, but when you do – when is it finished?

Oopps! Upgrade your browser pretty please. Oopps! Upgrade your browser pretty please.

Shinking a database file can be a sour lesson if you don’t understand what it does. Several other blogs have already good descriptions of that. “Shrink is the path to the Dark Side” as Paul S. Randal describes it. Same goes to Auto-Shrink.  But in the rare cases you need to run it – How long will it take? Hard to guess in advance, but a “guesstimate” can be fetched by running this query after starting a shrink (run in separate mgm studio window):

select session_id, start_time, percent_complete, estimated_completion_time
, DATEADD(ms,estimated_completion_time,GETDATE()) AS [EstimatedEndTime],
    (estimated_completion_time/1000/60) AS [EstimatedMinutesToEnd]
,cpu_time, total_elapsed_time, reads, writes, logical_reads
, command
from sys.dm_exec_requests
where command = 'DbccFilesCompact'
/Jonas Bergström