< Back
Test-DbaNetworkLatency
Post
NAME Test-DbaNetworkLatency
SYNOPSIS
Tests how long a query takes to return from SQL Server
SYNTAX
Test-DbaNetworkLatency [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-Query] <String>] [[-Count] <Int>] [-EnableException <Switch>]
[<CommonParameters>]
DESCRIPTION
This function is intended to help measure SQL Server network latency by establishing a connection and executing a
simple query. This is a better than a simple ping because it actually creates the connection to the SQL Server and
measures the time required for only the entire routine, but the duration of the query as well how long it takes
for the results to be returned.
By default, this command will execute "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" three times. It will then
output how long the entire connection and command took, as well as how long *only* the execution of the command
took.
This allows you to see if the issue is with the connection or the SQL Server itself.
PARAMETERS
-Count [<Int>]
Specifies how many times the query should be executed. By default, the query is executed three times.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Query [<String>]
Specifies the query to be executed. By default, "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" will be
executed on master. To execute in other databases, use fully qualified object names.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The SQL Server you want to run the test on.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Object[]
NOTES
Tags: Performance, Network
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster
Tests the round trip return of "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" on sqlserver2014a and sqlcluster
using Windows credentials.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Test-DbaNetworkLatency -SqlInstance sqlserver2014a -SqlCredential $cred
Tests the execution results return of "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" on sqlserver2014a using
SQL credentials.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from
otherdb.dbo.table" -Count 10
Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a,
sqlcluster, and sqlserver using Windows credentials.
RELATED LINKS
https://dbatools.io/Test-DbaNetworkLatency
SYNOPSIS
Tests how long a query takes to return from SQL Server
SYNTAX
Test-DbaNetworkLatency [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-Query] <String>] [[-Count] <Int>] [-EnableException <Switch>]
[<CommonParameters>]
DESCRIPTION
This function is intended to help measure SQL Server network latency by establishing a connection and executing a
simple query. This is a better than a simple ping because it actually creates the connection to the SQL Server and
measures the time required for only the entire routine, but the duration of the query as well how long it takes
for the results to be returned.
By default, this command will execute "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" three times. It will then
output how long the entire connection and command took, as well as how long *only* the execution of the command
took.
This allows you to see if the issue is with the connection or the SQL Server itself.
PARAMETERS
-Count [<Int>]
Specifies how many times the query should be executed. By default, the query is executed three times.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Query [<String>]
Specifies the query to be executed. By default, "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" will be
executed on master. To execute in other databases, use fully qualified object names.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The SQL Server you want to run the test on.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
System.Object[]
NOTES
Tags: Performance, Network
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster
Tests the round trip return of "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" on sqlserver2014a and sqlcluster
using Windows credentials.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Test-DbaNetworkLatency -SqlInstance sqlserver2014a -SqlCredential $cred
Tests the execution results return of "SELECT TOP 100 * FROM INFORMATION_SCHEMA.TABLES" on sqlserver2014a using
SQL credentials.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from
otherdb.dbo.table" -Count 10
Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a,
sqlcluster, and sqlserver using Windows credentials.
RELATED LINKS
https://dbatools.io/Test-DbaNetworkLatency