Skip to content

Commit 72d9609

Browse files
authored
Merge branch 'dev' into AddFixOrphanUsersOption
2 parents 4364d2c + 1d31d5a commit 72d9609

3 files changed

Lines changed: 89 additions & 54 deletions

File tree

sp_Blitz.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3879,9 +3879,9 @@ AS
38793879

38803880
IF (@ProductVersionMajor = 15 AND @ProductVersionMinor < 2000) OR
38813881
(@ProductVersionMajor = 14 AND @ProductVersionMinor < 1000) OR
3882-
(@ProductVersionMajor = 13 AND @ProductVersionMinor < 5026) OR
3882+
(@ProductVersionMajor = 13 AND @ProductVersionMinor < 6300) OR
38833883
(@ProductVersionMajor = 12 AND @ProductVersionMinor < 6024) OR
3884-
(@ProductVersionMajor = 11 AND @ProductVersionMinor < 7001) OR
3884+
(@ProductVersionMajor = 11 /*AND @ProductVersionMinor < 7001)*/ OR
38853885
(@ProductVersionMajor = 10.5 /*AND @ProductVersionMinor < 6000*/) OR
38863886
(@ProductVersionMajor = 10 /*AND @ProductVersionMinor < 6000*/) OR
38873887
(@ProductVersionMajor = 9 /*AND @ProductVersionMinor <= 5000*/)
@@ -3892,7 +3892,7 @@ AS
38923892
INSERT INTO #BlitzResults(CheckID, Priority, FindingsGroup, Finding, URL, Details)
38933893
VALUES(128, 20, 'Reliability', 'Unsupported Build of SQL Server', 'https://www.brentozar.com/go/unsupported',
38943894
'Version ' + CAST(@ProductVersionMajor AS VARCHAR(100)) +
3895-
CASE WHEN @ProductVersionMajor >= 11 THEN
3895+
CASE WHEN @ProductVersionMajor >= 12 THEN
38963896
'.' + CAST(@ProductVersionMinor AS VARCHAR(100)) + ' is no longer supported by Microsoft. You need to apply a service pack.'
38973897
ELSE ' is no longer supported by Microsoft. You should be making plans to upgrade to a modern version of SQL Server.' END);
38983898
END;

sp_BlitzLock.sql

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ BEGIN
150150
WHEN
151151
(
152152
SELECT
153-
SERVERPROPERTY('EDITION')
154-
) = 'SQL Azure'
153+
CONVERT
154+
(
155+
integer,
156+
SERVERPROPERTY('EngineEdition')
157+
)
158+
) = 5
155159
THEN 1
156160
ELSE 0
157161
END,
@@ -379,7 +383,7 @@ BEGIN
379383
/*Add wait_resource column*/
380384
ALTER TABLE ' +
381385
@ObjectFullName +
382-
N' ADD client_option_1 nvarchar(8000) NULL;';
386+
N' ADD client_option_1 varchar(500) NULL;';
383387

384388
IF @Debug = 1 BEGIN PRINT @StringToExecute; END;
385389
EXEC sys.sp_executesql
@@ -395,7 +399,7 @@ BEGIN
395399
/*Add wait_resource column*/
396400
ALTER TABLE ' +
397401
@ObjectFullName +
398-
N' ADD client_option_2 nvarchar(8000) NULL;';
402+
N' ADD client_option_2 varchar(500) NULL;';
399403

400404
IF @Debug = 1 BEGIN PRINT @StringToExecute; END;
401405
EXEC sys.sp_executesql
@@ -458,8 +462,8 @@ BEGIN
458462
waiter_mode nvarchar(256),
459463
lock_mode nvarchar(256),
460464
transaction_count bigint,
461-
client_option_1 varchar(2000),
462-
client_option_2 varchar(2000),
465+
client_option_1 varchar(500),
466+
client_option_2 varchar(500),
463467
login_name nvarchar(256),
464468
host_name nvarchar(256),
465469
client_app nvarchar(1024),
@@ -845,7 +849,12 @@ BEGIN
845849
LEFT JOIN #t AS t
846850
ON 1 = 1
847851
CROSS APPLY x.x.nodes('/RingBufferTarget/event') AS e(x)
848-
WHERE e.x.exist('@name[ .= "xml_deadlock_report"]') = 1
852+
WHERE
853+
(
854+
e.x.exist('@name[ .= "xml_deadlock_report"]') = 1
855+
OR e.x.exist('@name[ .= "database_xml_deadlock_report"]') = 1
856+
OR e.x.exist('@name[ .= "xml_deadlock_report_filtered"]') = 1
857+
)
849858
AND e.x.exist('@timestamp[. >= sql:variable("@StartDate")]') = 1
850859
AND e.x.exist('@timestamp[. < sql:variable("@EndDate")]') = 1
851860
OPTION(RECOMPILE);
@@ -864,7 +873,9 @@ BEGIN
864873
SET @d = CONVERT(varchar(40), GETDATE(), 109);
865874
RAISERROR('Inserting to #deadlock_data for event file data', 0, 1) WITH NOWAIT;
866875

867-
INSERT
876+
IF @Debug = 1 BEGIN SET STATISTICS XML ON; END;
877+
878+
INSERT
868879
#deadlock_data WITH(TABLOCKX)
869880
(
870881
deadlock_xml
@@ -876,12 +887,19 @@ BEGIN
876887
LEFT JOIN #t AS t
877888
ON 1 = 1
878889
CROSS APPLY x.x.nodes('/event') AS e(x)
879-
WHERE e.x.exist('/event/@name[ .= "xml_deadlock_report"]') = 1
880-
AND e.x.exist('/event/@timestamp[. >= sql:variable("@StartDate")]') = 1
881-
AND e.x.exist('/event/@timestamp[. < sql:variable("@EndDate")]') = 1
890+
WHERE
891+
(
892+
e.x.exist('@name[ .= "xml_deadlock_report"]') = 1
893+
OR e.x.exist('@name[ .= "database_xml_deadlock_report"]') = 1
894+
OR e.x.exist('@name[ .= "xml_deadlock_report_filtered"]') = 1
895+
)
896+
AND e.x.exist('@timestamp[. >= sql:variable("@StartDate")]') = 1
897+
AND e.x.exist('@timestamp[. < sql:variable("@EndDate")]') = 1
882898
OPTION(RECOMPILE);
883899

884-
SET @d = CONVERT(varchar(40), GETDATE(), 109);
900+
IF @Debug = 1 BEGIN SET STATISTICS XML OFF; END;
901+
902+
SET @d = CONVERT(varchar(40), GETDATE(), 109);
885903
RAISERROR('Finished at %s', 0, 1, @d) WITH NOWAIT;
886904
END;
887905

@@ -908,7 +926,7 @@ BEGIN
908926
FROM sys.fn_xe_file_target_read_file(N'system_health*.xel', NULL, NULL, NULL) AS fx
909927
LEFT JOIN #t AS t
910928
ON 1 = 1
911-
WHERE fx.object_name = N'xml_deadlock_report'
929+
WHERE fx.object_name = N'xml_deadlock_report'
912930
) AS xml
913931
CROSS APPLY xml.deadlock_xml.nodes('/event') AS e(x)
914932
WHERE 1 = 1
@@ -1006,7 +1024,7 @@ BEGIN
10061024
CASE WHEN q.clientoption1 & 8192 = 8192 THEN ', NUMERIC_ROUNDABORT' ELSE '' END +
10071025
CASE WHEN q.clientoption1 & 16384 = 16384 THEN ', XACT_ABORT' ELSE '' END,
10081026
3,
1009-
8000
1027+
500
10101028
),
10111029
client_option_2 =
10121030
SUBSTRING
@@ -1028,7 +1046,7 @@ BEGIN
10281046
CASE WHEN q.clientoption2 & 1073741824 = 1073741824 THEN ', AUTO UPDATE STATISTICS' ELSE '' END +
10291047
CASE WHEN q.clientoption2 & 1469283328 = 1469283328 THEN ', ALL SETTABLE OPTIONS' ELSE '' END,
10301048
3,
1031-
8000
1049+
500
10321050
),
10331051
q.process_xml
10341052
INTO #deadlock_process
@@ -1795,6 +1813,16 @@ BEGIN
17951813
N'S',
17961814
N'IS'
17971815
)
1816+
OR dow.owner_mode IN
1817+
(
1818+
N'S',
1819+
N'IS'
1820+
)
1821+
OR dow.waiter_mode IN
1822+
(
1823+
N'S',
1824+
N'IS'
1825+
)
17981826
AND (dow.database_id = @DatabaseId OR @DatabaseName IS NULL)
17991827
AND (dow.event_date >= @StartDate OR @StartDate IS NULL)
18001828
AND (dow.event_date < @EndDate OR @EndDate IS NULL)
@@ -2532,7 +2560,7 @@ BEGIN
25322560
),
25332561
14
25342562
)
2535-
END
2563+
END
25362564
FROM #deadlock_owner_waiter AS dow
25372565
JOIN #deadlock_process AS dp
25382566
ON (dp.id = dow.owner_id
@@ -3520,38 +3548,40 @@ BEGIN
35203548
DROP SYNONYM DeadlockFindings; /*done with inserting.*/
35213549
END;
35223550
ELSE /*Output to database is not set output to client app*/
3523-
SET @d = CONVERT(varchar(40), GETDATE(), 109);
3524-
RAISERROR('Results to client %s', 0, 1, @d) WITH NOWAIT;
3525-
3526-
IF @Debug = 1 BEGIN SET STATISTICS XML ON; END;
3527-
3528-
EXEC sys.sp_executesql
3529-
@deadlock_result;
3530-
3531-
IF @Debug = 1
3532-
BEGIN
3533-
SET STATISTICS XML OFF;
3534-
PRINT @deadlock_result;
3535-
END;
3536-
3537-
RAISERROR('Finished at %s', 0, 1, @d) WITH NOWAIT;
3538-
3539-
SET @d = CONVERT(varchar(40), GETDATE(), 109);
3540-
RAISERROR('Returning findings %s', 0, 1, @d) WITH NOWAIT;
3541-
3542-
SELECT
3543-
df.check_id,
3544-
df.database_name,
3545-
df.object_name,
3546-
df.finding_group,
3547-
df.finding
3548-
FROM #deadlock_findings AS df
3549-
ORDER BY df.check_id
3550-
OPTION(RECOMPILE);
3551-
3552-
SET @d = CONVERT(varchar(40), GETDATE(), 109);
3553-
RAISERROR('Finished at %s', 0, 1, @d) WITH NOWAIT;
3554-
END; /*done with output to client app.*/
3551+
BEGIN
3552+
SET @d = CONVERT(varchar(40), GETDATE(), 109);
3553+
RAISERROR('Results to client %s', 0, 1, @d) WITH NOWAIT;
3554+
3555+
IF @Debug = 1 BEGIN SET STATISTICS XML ON; END;
3556+
3557+
EXEC sys.sp_executesql
3558+
@deadlock_result;
3559+
3560+
IF @Debug = 1
3561+
BEGIN
3562+
SET STATISTICS XML OFF;
3563+
PRINT @deadlock_result;
3564+
END;
3565+
3566+
RAISERROR('Finished at %s', 0, 1, @d) WITH NOWAIT;
3567+
3568+
SET @d = CONVERT(varchar(40), GETDATE(), 109);
3569+
RAISERROR('Returning findings %s', 0, 1, @d) WITH NOWAIT;
3570+
3571+
SELECT
3572+
df.check_id,
3573+
df.database_name,
3574+
df.object_name,
3575+
df.finding_group,
3576+
df.finding
3577+
FROM #deadlock_findings AS df
3578+
ORDER BY df.check_id
3579+
OPTION(RECOMPILE);
3580+
3581+
SET @d = CONVERT(varchar(40), GETDATE(), 109);
3582+
RAISERROR('Finished at %s', 0, 1, @d) WITH NOWAIT;
3583+
END; /*done with output to client app.*/
3584+
END;
35553585

35563586
IF @Debug = 1
35573587
BEGIN

sp_DatabaseRestore.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ BEGIN
900900
/* now take split backups into account */
901901
IF (SELECT COUNT(*) FROM #SplitFullBackups) > 0
902902
BEGIN
903-
RAISERROR('Split backups found', 0, 1) WITH NOWAIT;
903+
IF @Debug = 1 RAISERROR('Split backups found', 0, 1) WITH NOWAIT;
904904

905905
SET @sql = N'RESTORE DATABASE ' + @RestoreDatabaseName + N' FROM '
906906
+ STUFF(
@@ -1093,7 +1093,7 @@ BEGIN
10931093

10941094
IF (SELECT COUNT(*) FROM #SplitDiffBackups) > 0
10951095
BEGIN
1096-
RAISERROR ('Split backups found', 0, 1) WITH NOWAIT;
1096+
IF @Debug = 1 RAISERROR ('Split backups found', 0, 1) WITH NOWAIT;
10971097
SET @sql = N'RESTORE DATABASE ' + @RestoreDatabaseName + N' FROM '
10981098
+ STUFF(
10991099
(SELECT CHAR( 10 ) + ',DISK=''' + BackupPath + BackupFile + ''''
@@ -1375,6 +1375,7 @@ BEGIN
13751375
AND REPLACE( RIGHT( REPLACE( fl.BackupFile, RIGHT( fl.BackupFile, PATINDEX( '%_[0-9][0-9]%', REVERSE( fl.BackupFile ) ) ), '' ), 16 ), '_', '' ) > @StopAt
13761376
ORDER BY BackupFile;
13771377
END
1378+
13781379
IF @ExtraLogFile IS NULL
13791380
BEGIN
13801381
DELETE fl
@@ -1385,6 +1386,10 @@ BEGIN
13851386
END
13861387
ELSE
13871388
BEGIN
1389+
-- If this is a split backup, @ExtraLogFile contains only the first split backup file, either _1.trn or _01.trn
1390+
-- Change @ExtraLogFile to the max split backup file, then delete all log files greater than this
1391+
SET @ExtraLogFile = REPLACE(REPLACE(@ExtraLogFile, '_1.trn', '_9.trn'), '_01.trn', '_64.trn')
1392+
13881393
DELETE fl
13891394
FROM @FileList AS fl
13901395
WHERE BackupFile LIKE N'%.trn'
@@ -1447,7 +1452,7 @@ WHERE BackupFile IS NOT NULL;
14471452

14481453
IF (SELECT COUNT( * ) FROM #SplitLogBackups WHERE DenseRank = @LogRestoreRanking) > 1
14491454
BEGIN
1450-
RAISERROR ('Split backups found', 0, 1) WITH NOWAIT;
1455+
IF @Debug = 1 RAISERROR ('Split backups found', 0, 1) WITH NOWAIT;
14511456
SET @sql = N'RESTORE LOG ' + @RestoreDatabaseName + N' FROM '
14521457
+ STUFF(
14531458
(SELECT CHAR( 10 ) + ',DISK=''' + BackupPath + BackupFile + ''''

0 commit comments

Comments
 (0)