diff --git a/bin/dbatools-index.json b/bin/dbatools-index.json index 4d887d20fb..0af6922f81 100644 Binary files a/bin/dbatools-index.json and b/bin/dbatools-index.json differ diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2008.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2008.sql index 0d7f5278be..fde9f5897a 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2008.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2008.sql @@ -1,7 +1,7 @@ -- SQL Server 2008 Diagnostic Information Queries -- Glenn Berry --- Last Modified: January 3, 2023 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -14,7 +14,7 @@ -- Please make sure you are using the correct version of these diagnostic queries for your version of SQL Server --****************************************************************************** ---* Copyright (C) 2023 Glenn Berry +--* Copyright (C) 2024 Glenn Berry --* All rights reserved. --* --* @@ -141,18 +141,24 @@ SERVERPROPERTY('IsIntegratedSecurityOnly') AS [IsIntegratedSecurityOnly]; -- Get SQL Server Agent jobs and Category information (Query 4) (SQL Server Agent Jobs) -SELECT sj.name AS [Job Name], sj.[description] AS [Job Description], SUSER_SNAME(sj.owner_sid) AS [Job Owner], +SELECT sj.name AS [Job Name], sj.[description] AS [Job Description], +sc.name AS [CategoryName], SUSER_SNAME(sj.owner_sid) AS [Job Owner], sj.date_created AS [Date Created], sj.[enabled] AS [Job Enabled], -sj.notify_email_operator_id, sj.notify_level_email, sc.name AS [CategoryName], -s.[enabled] AS [Sched Enabled], js.next_run_date, js.next_run_time +sj.notify_email_operator_id, sj.notify_level_email, h.run_status, +RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], +CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN + (SELECT job_id, instance_id = MAX(instance_id) + FROM msdb.dbo.sysjobhistory WITH (NOLOCK) + GROUP BY job_id) AS l +ON sj.job_id = l.job_id +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -LEFT OUTER JOIN msdb.dbo.sysjobschedules AS js WITH (NOLOCK) -ON sj.job_id = js.job_id -LEFT OUTER JOIN msdb.dbo.sysschedules AS s WITH (NOLOCK) -ON js.schedule_id = s.schedule_id -ORDER BY sj.name OPTION (RECOMPILE); +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +ON h.job_id = l.job_id +AND h.instance_id = l.instance_id +ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); ------ -- Gives you some basic information about your SQL Server Agent jobs, who owns them and how they are configured diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2008R2.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2008R2.sql index c48450bccd..d201fa3ac2 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2008R2.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2008R2.sql @@ -1,7 +1,7 @@ -- SQL Server 2008 R2 Diagnostic Information Queries -- Glenn Berry --- Last Modified: January 3, 2023 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -14,7 +14,7 @@ -- Please make sure you are using the correct version of these diagnostic queries for your version of SQL Server --****************************************************************************** ---* Copyright (C) 2023 Glenn Berry +--* Copyright (C) 2024 Glenn Berry --* All rights reserved. --* --* @@ -139,18 +139,24 @@ SERVERPROPERTY('IsIntegratedSecurityOnly') AS [IsIntegratedSecurityOnly]; -- Get SQL Server Agent jobs and Category information (Query 4) (SQL Server Agent Jobs) -SELECT sj.name AS [Job Name], sj.[description] AS [Job Description], SUSER_SNAME(sj.owner_sid) AS [Job Owner], +SELECT sj.name AS [Job Name], sj.[description] AS [Job Description], +sc.name AS [CategoryName], SUSER_SNAME(sj.owner_sid) AS [Job Owner], sj.date_created AS [Date Created], sj.[enabled] AS [Job Enabled], -sj.notify_email_operator_id, sj.notify_level_email, sc.name AS [CategoryName], -s.[enabled] AS [Sched Enabled], js.next_run_date, js.next_run_time +sj.notify_email_operator_id, sj.notify_level_email, h.run_status, +RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], +CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN + (SELECT job_id, instance_id = MAX(instance_id) + FROM msdb.dbo.sysjobhistory WITH (NOLOCK) + GROUP BY job_id) AS l +ON sj.job_id = l.job_id +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -LEFT OUTER JOIN msdb.dbo.sysjobschedules AS js WITH (NOLOCK) -ON sj.job_id = js.job_id -LEFT OUTER JOIN msdb.dbo.sysschedules AS s WITH (NOLOCK) -ON js.schedule_id = s.schedule_id -ORDER BY sj.name OPTION (RECOMPILE); +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +ON h.job_id = l.job_id +AND h.instance_id = l.instance_id +ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); ------ -- Gives you some basic information about your SQL Server Agent jobs, who owns them and how they are configured diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql index 66c179f866..c3b538dd58 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql @@ -1,7 +1,7 @@ -- SQL Server 2012 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 7, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -370,14 +370,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql index 3a32208f39..9a2ad8b781 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql @@ -1,7 +1,7 @@ -- SQL Server 2014 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 7, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -364,14 +364,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql index 902fd6b8bf..de2807bfb5 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql @@ -1,7 +1,7 @@ -- SQL Server 2016 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 7, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -346,14 +346,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql index 9a8fe73b6e..8170407e68 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql @@ -1,7 +1,7 @@ -- SQL Server 2016 SP2 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 7, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -328,14 +328,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql index 8aced14b00..16f1113097 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql @@ -1,7 +1,7 @@ -- SQL Server 2017 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 7, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -349,14 +349,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql index e43e4aa812..41808c4c77 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql @@ -1,7 +1,7 @@ -- SQL Server 2019 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 15, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -331,14 +331,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql index b712a0bc66..47e907835a 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql @@ -1,7 +1,7 @@ -- SQL Server 2022 Diagnostic Information Queries -- Glenn Berry --- Last Modified: February 7, 2024 +-- Last Modified: March 6, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -329,14 +329,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status, RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS], CONVERT(DATETIME, RTRIM(h.run_date) + ' ' + STUFF(STUFF(REPLACE(STR(RTRIM(h.run_time),6,0),' ','0'),3,0,':'),6,0,':')) AS [Last Start Date] FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK) -INNER JOIN +LEFT OUTER JOIN (SELECT job_id, instance_id = MAX(instance_id) FROM msdb.dbo.sysjobhistory WITH (NOLOCK) GROUP BY job_id) AS l ON sj.job_id = l.job_id -INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK) ON sj.category_id = sc.category_id -INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) +LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK) ON h.job_id = l.job_id AND h.instance_id = l.instance_id ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE); diff --git a/dbatools.psd1 b/dbatools.psd1 index 11bee38423..a68fab99e8 100644 --- a/dbatools.psd1 +++ b/dbatools.psd1 @@ -11,7 +11,7 @@ RootModule = 'dbatools.psm1' # Version number of this module. - ModuleVersion = '2.1.8' + ModuleVersion = '2.1.9' # ID used to uniquely identify this module GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'