dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.39k stars 787 forks source link

Get-DbaAgentJob slowness on applying DatabaseName filter #9332

Open xshen1 opened 2 months ago

xshen1 commented 2 months ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

No errors, just lots of time spent waiting for output when we want to return job with Database filter

Steps to Reproduce

 Get-DbaAgentJob -SqlInstance sqlserver2014a -Database test_database

Please confirm that you are running the most recent version of dbatools

It takes around 30~40 min of each calling if we choose to apply -Database filter

Other details or mentions

            if ($Database) {
                $jobs = $jobs | Where-Object { $_.JobSteps | Where-Object DatabaseName -in $Database }
            }

this is more like n^2log(n) wonder if we can use the first jobstep or something to reduce the filter time by a lot

What PowerShell host was used when producing this error

Windows PowerShell ISE (powershell_ise.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.17763.5576
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.5576
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU25) (KB5033688) - 15.0.4355.3 (X64) Jan 30 2024 17:02:22 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

PSChildName Version


Client 4.8.03761 Full 4.8.03761 Client 4.0.0.0

wsmelton commented 2 months ago

30-40 minutes?!?!

xshen1 commented 1 month ago

We got like 10 job per db. A LOT of DBs and on average 4~5 steps per job. Yeap same result ummm

wsmelton commented 1 month ago

A LOT of DBs? Is that under 100, over 500, under 3,000? (Everyone's definition of a lot isn't the same 😉)

Be aware that if you have a large instance (once you get over ~1k databases) then the performance can play in from your master database on performance. What are the waits showing on the sessions for your scripts?