Thor Logo dbatools

Get-DbaEstimatedCompletionTime

View Source
Chrissy LeMaire (@cl), netnerds.net
Windows, Linux, macOS

Synopsis

Monitors progress and estimated completion times for long-running SQL Server operations

Description

Retrieves real-time progress information for long-running SQL Server maintenance and administrative operations by querying sys.dm_exec_requests. This function helps DBAs monitor the status of time-intensive tasks without having to guess when they’ll complete or manually check SQL Server Management Studio.

Shows progress details including percent complete, running time, estimated time remaining, and projected completion time. Only returns operations that SQL Server can provide completion estimates for - quick queries and standard SELECT statements won’t appear in the results.

Percent complete will show for the following commands:

ALTER INDEX REORGANIZE
AUTO_SHRINK option with ALTER DATABASE
BACKUP DATABASE
DBCC CHECKDB
DBCC CHECKFILEGROUP
DBCC CHECKTABLE
DBCC INDEXDEFRAG
DBCC SHRINKDATABASE
DBCC SHRINKFILE
RECOVERY
RESTORE DATABASE
ROLLBACK
TDE ENCRYPTION

Particularly useful during scheduled maintenance windows, large database restores, or when troubleshooting performance issues where you need visibility into what’s currently running and how much longer it will take.

For additional information, check out https://blogs.sentryone.com/loriedwards/patience-dm-exec-requests/ and https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-exec-requests-transact-sql

Syntax

Get-DbaEstimatedCompletionTime
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaEstimatedCompletionTime -SqlInstance sql2016

Gets estimated completion times for queries performed against the entire server

Example: 2
PS C:\> Get-DbaEstimatedCompletionTime -SqlInstance sql2016 | Select-Object *

Gets estimated completion times for queries performed against the entire server PLUS the SQL query text of each command

Example: 3
PS C:\> Get-DbaEstimatedCompletionTime -SqlInstance sql2016 | Where-Object { $_.Text -match 'somequerytext' }

Gets results for commands whose queries only match specific text (match is like LIKE but way more powerful)

Example: 4
PS C:\> Get-DbaEstimatedCompletionTime -SqlInstance sql2016 -Database Northwind,pubs,Adventureworks2014

Gets estimated completion times for queries performed against the Northwind, pubs, and Adventureworks2014 databases

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (ByValue)
Default Value

Optional Parameters

-SqlCredential

SqlLogin to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance..

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Database

Filters results to show only long-running operations within the specified database(s). Accepts multiple database names or wildcards.
Use this when you need to monitor specific databases during maintenance windows or troubleshoot performance issues in particular databases.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ExcludeDatabase

Excludes long-running operations from the specified database(s) when monitoring across the entire instance.
Helpful when you want to monitor all databases except system databases or exclude databases with known maintenance operations.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with “sea of red” exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this “nice by default” feature off and enables you to catch exceptions with your own try/catch.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse