Skip to content

Commit 2d35be3

Browse files
2.1.9
1 parent da391a9 commit 2d35be3

11 files changed

+63
-51
lines changed

bin/dbatools-index.json

2.47 KB
Binary file not shown.

bin/diagnosticquery/SQLServerDiagnosticQueries_2008.sql

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2008 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: January 3, 2023
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -14,7 +14,7 @@
1414
-- Please make sure you are using the correct version of these diagnostic queries for your version of SQL Server
1515

1616
--******************************************************************************
17-
--* Copyright (C) 2023 Glenn Berry
17+
--* Copyright (C) 2024 Glenn Berry
1818
--* All rights reserved.
1919
--*
2020
--*
@@ -141,18 +141,24 @@ SERVERPROPERTY('IsIntegratedSecurityOnly') AS [IsIntegratedSecurityOnly];
141141

142142

143143
-- Get SQL Server Agent jobs and Category information (Query 4) (SQL Server Agent Jobs)
144-
SELECT sj.name AS [Job Name], sj.[description] AS [Job Description], SUSER_SNAME(sj.owner_sid) AS [Job Owner],
144+
SELECT sj.name AS [Job Name], sj.[description] AS [Job Description],
145+
sc.name AS [CategoryName], SUSER_SNAME(sj.owner_sid) AS [Job Owner],
145146
sj.date_created AS [Date Created], sj.[enabled] AS [Job Enabled],
146-
sj.notify_email_operator_id, sj.notify_level_email, sc.name AS [CategoryName],
147-
s.[enabled] AS [Sched Enabled], js.next_run_date, js.next_run_time
147+
sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
148+
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
149+
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]
148150
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
149-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
151+
LEFT OUTER JOIN
152+
(SELECT job_id, instance_id = MAX(instance_id)
153+
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
154+
GROUP BY job_id) AS l
155+
ON sj.job_id = l.job_id
156+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
150157
ON sj.category_id = sc.category_id
151-
LEFT OUTER JOIN msdb.dbo.sysjobschedules AS js WITH (NOLOCK)
152-
ON sj.job_id = js.job_id
153-
LEFT OUTER JOIN msdb.dbo.sysschedules AS s WITH (NOLOCK)
154-
ON js.schedule_id = s.schedule_id
155-
ORDER BY sj.name OPTION (RECOMPILE);
158+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
159+
ON h.job_id = l.job_id
160+
AND h.instance_id = l.instance_id
161+
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);
156162
------
157163

158164
-- Gives you some basic information about your SQL Server Agent jobs, who owns them and how they are configured

bin/diagnosticquery/SQLServerDiagnosticQueries_2008R2.sql

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2008 R2 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: January 3, 2023
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -14,7 +14,7 @@
1414
-- Please make sure you are using the correct version of these diagnostic queries for your version of SQL Server
1515

1616
--******************************************************************************
17-
--* Copyright (C) 2023 Glenn Berry
17+
--* Copyright (C) 2024 Glenn Berry
1818
--* All rights reserved.
1919
--*
2020
--*
@@ -139,18 +139,24 @@ SERVERPROPERTY('IsIntegratedSecurityOnly') AS [IsIntegratedSecurityOnly];
139139

140140

141141
-- Get SQL Server Agent jobs and Category information (Query 4) (SQL Server Agent Jobs)
142-
SELECT sj.name AS [Job Name], sj.[description] AS [Job Description], SUSER_SNAME(sj.owner_sid) AS [Job Owner],
142+
SELECT sj.name AS [Job Name], sj.[description] AS [Job Description],
143+
sc.name AS [CategoryName], SUSER_SNAME(sj.owner_sid) AS [Job Owner],
143144
sj.date_created AS [Date Created], sj.[enabled] AS [Job Enabled],
144-
sj.notify_email_operator_id, sj.notify_level_email, sc.name AS [CategoryName],
145-
s.[enabled] AS [Sched Enabled], js.next_run_date, js.next_run_time
145+
sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
146+
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
147+
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]
146148
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
147-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
149+
LEFT OUTER JOIN
150+
(SELECT job_id, instance_id = MAX(instance_id)
151+
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
152+
GROUP BY job_id) AS l
153+
ON sj.job_id = l.job_id
154+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
148155
ON sj.category_id = sc.category_id
149-
LEFT OUTER JOIN msdb.dbo.sysjobschedules AS js WITH (NOLOCK)
150-
ON sj.job_id = js.job_id
151-
LEFT OUTER JOIN msdb.dbo.sysschedules AS s WITH (NOLOCK)
152-
ON js.schedule_id = s.schedule_id
153-
ORDER BY sj.name OPTION (RECOMPILE);
156+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
157+
ON h.job_id = l.job_id
158+
AND h.instance_id = l.instance_id
159+
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);
154160
------
155161

156162
-- Gives you some basic information about your SQL Server Agent jobs, who owns them and how they are configured

bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2012 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 7, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -370,14 +370,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
370370
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
371371
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]
372372
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
373-
INNER JOIN
373+
LEFT OUTER JOIN
374374
(SELECT job_id, instance_id = MAX(instance_id)
375375
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
376376
GROUP BY job_id) AS l
377377
ON sj.job_id = l.job_id
378-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
378+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
379379
ON sj.category_id = sc.category_id
380-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
380+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
381381
ON h.job_id = l.job_id
382382
AND h.instance_id = l.instance_id
383383
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2014 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 7, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -364,14 +364,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
364364
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
365365
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]
366366
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
367-
INNER JOIN
367+
LEFT OUTER JOIN
368368
(SELECT job_id, instance_id = MAX(instance_id)
369369
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
370370
GROUP BY job_id) AS l
371371
ON sj.job_id = l.job_id
372-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
372+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
373373
ON sj.category_id = sc.category_id
374-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
374+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
375375
ON h.job_id = l.job_id
376376
AND h.instance_id = l.instance_id
377377
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2016 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 7, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -346,14 +346,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
346346
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
347347
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]
348348
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
349-
INNER JOIN
349+
LEFT OUTER JOIN
350350
(SELECT job_id, instance_id = MAX(instance_id)
351351
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
352352
GROUP BY job_id) AS l
353353
ON sj.job_id = l.job_id
354-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
354+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
355355
ON sj.category_id = sc.category_id
356-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
356+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
357357
ON h.job_id = l.job_id
358358
AND h.instance_id = l.instance_id
359359
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2016 SP2 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 7, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -328,14 +328,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
328328
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
329329
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]
330330
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
331-
INNER JOIN
331+
LEFT OUTER JOIN
332332
(SELECT job_id, instance_id = MAX(instance_id)
333333
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
334334
GROUP BY job_id) AS l
335335
ON sj.job_id = l.job_id
336-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
336+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
337337
ON sj.category_id = sc.category_id
338-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
338+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
339339
ON h.job_id = l.job_id
340340
AND h.instance_id = l.instance_id
341341
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2017 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 7, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -349,14 +349,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
349349
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
350350
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]
351351
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
352-
INNER JOIN
352+
LEFT OUTER JOIN
353353
(SELECT job_id, instance_id = MAX(instance_id)
354354
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
355355
GROUP BY job_id) AS l
356356
ON sj.job_id = l.job_id
357-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
357+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
358358
ON sj.category_id = sc.category_id
359-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
359+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
360360
ON h.job_id = l.job_id
361361
AND h.instance_id = l.instance_id
362362
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2019 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 15, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -331,14 +331,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
331331
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
332332
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]
333333
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
334-
INNER JOIN
334+
LEFT OUTER JOIN
335335
(SELECT job_id, instance_id = MAX(instance_id)
336336
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
337337
GROUP BY job_id) AS l
338338
ON sj.job_id = l.job_id
339-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
339+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
340340
ON sj.category_id = sc.category_id
341-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
341+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
342342
ON h.job_id = l.job_id
343343
AND h.instance_id = l.instance_id
344344
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
-- SQL Server 2022 Diagnostic Information Queries
33
-- Glenn Berry
4-
-- Last Modified: February 7, 2024
4+
-- Last Modified: March 6, 2024
55
-- https://glennsqlperformance.com/
66
-- https://sqlserverperformance.wordpress.com/
77
-- YouTube: https://bit.ly/2PkoAM1
@@ -329,14 +329,14 @@ sj.notify_email_operator_id, sj.notify_level_email, h.run_status,
329329
RIGHT(STUFF(STUFF(REPLACE(STR(h.run_duration, 7, 0), ' ', '0'), 4, 0, ':'), 7, 0, ':'),8) AS [Last Duration - HHMMSS],
330330
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]
331331
FROM msdb.dbo.sysjobs AS sj WITH (NOLOCK)
332-
INNER JOIN
332+
LEFT OUTER JOIN
333333
(SELECT job_id, instance_id = MAX(instance_id)
334334
FROM msdb.dbo.sysjobhistory WITH (NOLOCK)
335335
GROUP BY job_id) AS l
336336
ON sj.job_id = l.job_id
337-
INNER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
337+
LEFT OUTER JOIN msdb.dbo.syscategories AS sc WITH (NOLOCK)
338338
ON sj.category_id = sc.category_id
339-
INNER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
339+
LEFT OUTER JOIN msdb.dbo.sysjobhistory AS h WITH (NOLOCK)
340340
ON h.job_id = l.job_id
341341
AND h.instance_id = l.instance_id
342342
ORDER BY CONVERT(INT, h.run_duration) DESC, [Last Start Date] DESC OPTION (RECOMPILE);

dbatools.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'dbatools.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2.1.8'
14+
ModuleVersion = '2.1.9'
1515

1616
# ID used to uniquely identify this module
1717
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'

0 commit comments

Comments
 (0)