Author | Brandon Abshire, netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Get-DbaQueryExecutionTime on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaQueryExecutionTime.
Displays Stored Procedures and Ad hoc queries with the highest execution times. Works on SQL Server 2008 and above.
Quickly find slow query executions within a database. Results will include stored procedures and individual SQL statements.
Get-DbaQueryExecutionTime -SqlInstance <DbaInstanceParameter[]>
[-SqlCredential <PSCredential>]
[-Database <Object[]>]
[-ExcludeDatabase <Object[]>]
[-MaxResultsPerDb <Int32>]
[-MinExecs <Int32>]
[[-MinExecMs] <Int32>]
[[-ExcludeSystem]]
[-EnableException]
[<CommonParameters>]
PS C:\> Get-DbaQueryExecutionTime -SqlInstance sql2008, sqlserver2012
Return the top 100 slowest stored procedures or statements for servers sql2008 and sqlserver2012.
PS C:\> Get-DbaQueryExecutionTime -SqlInstance sql2008 -Database TestDB
Return the top 100 slowest stored procedures or statements on server sql2008 for only the TestDB database.
PS C:\> Get-DbaQueryExecutionTime -SqlInstance sql2008 -Database TestDB -MaxResultsPerDb 100 -MinExecs 200 -MinExecMs 1000
Return the top 100 slowest stored procedures or statements on server sql2008 for only the TestDB database, limiting results to queries with more than 200 total executions and an execution time over
1000ms or higher.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Login 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.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The database(s) to exclude - this list is auto-populated from the server
Alias | |
Required | False |
Pipeline | false |
Default Value |
Allows you to limit the number of results returned, as many systems can have very large amounts of query plans. Default value is 100 results.
Alias | |
Required | False |
Pipeline | false |
Default Value | 100 |
Allows you to limit the scope to queries that have been executed a minimum number of time. Default value is 100 executions.
Alias | |
Required | False |
Pipeline | false |
Default Value | 100 |
Allows you to limit the scope to queries with a specified average execution time. Default value is 500 (ms).
Alias | |
Required | False |
Pipeline | false |
Default Value | 500 |
Allows you to suppress output on system databases
Alias | ExcludeSystemDatabases |
Required | False |
Pipeline | false |
Default Value | False |
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.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |