Skip to content

Commit

Permalink
Merge pull request #511 from erikdarlingdata/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
erikdarlingdata authored Jan 21, 2025
2 parents 2cf07da + b90200a commit 31aa63c
Show file tree
Hide file tree
Showing 30 changed files with 495 additions and 473 deletions.
42 changes: 21 additions & 21 deletions Alerts/Alerts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GO
This script will set up alerts for high severity and corruption errors in SQL Server.
Copyright 2024 Darling Data, LLC
Copyright 2025 Darling Data, LLC
https://www.erikdarling.com/
For support, head over to GitHub:
Expand Down Expand Up @@ -53,7 +53,7 @@ DECLARE

RETURN;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 019',
@message_id = 0,
@severity = 19,
Expand All @@ -62,12 +62,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 019',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 020',
@message_id = 0,
@severity = 20,
Expand All @@ -76,12 +76,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 020',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 021',
@message_id = 0,
@severity = 21,
Expand All @@ -90,12 +90,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 021',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 022',
@message_id = 0,
@severity = 22,
Expand All @@ -104,12 +104,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 022',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 023',
@message_id = 0,
@severity = 23,
Expand All @@ -118,12 +118,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 023',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 024',
@message_id = 0,
@severity = 24,
Expand All @@ -132,12 +132,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 024',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Severity 025',
@message_id = 0,
@severity = 25,
Expand All @@ -146,12 +146,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Severity 025',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Error Number 823',
@message_id = 823,
@severity = 0,
Expand All @@ -160,12 +160,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Error Number 823',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Error Number 824',
@message_id = 824,
@severity = 0,
Expand All @@ -174,12 +174,12 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Error Number 824',
@operator_name = @operator_name,
@notification_method = 7;

EXEC msdb.dbo.sp_add_alert
EXECUTE msdb.dbo.sp_add_alert
@name = N'Error Number 825',
@message_id = 825,
@severity = 0,
Expand All @@ -188,7 +188,7 @@ EXEC msdb.dbo.sp_add_alert
@include_event_description_in = 1,
@job_id = N'00000000-0000-0000-0000-000000000000';

EXEC msdb.dbo.sp_add_notification
EXECUTE msdb.dbo.sp_add_notification
@alert_name = N'Error Number 825',
@operator_name = @operator_name,
@notification_method = 7;
16 changes: 8 additions & 8 deletions Clear Token Perm/ClearTokenPerm Agent Job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For background on why you might need this:
In short, if your security caches are growing out of control, it can cause all sorts of weird issues with SQL Server.
Copyright 2024 Darling Data, LLC
Copyright 2025 Darling Data, LLC
https://www.erikdarling.com/
For support, head over to GitHub:
Expand Down Expand Up @@ -52,7 +52,7 @@ IF NOT EXISTS
AND category_class = 1
)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category
EXECUTE @ReturnCode = msdb.dbo.sp_add_category
@class = N'JOB',
@type = N'LOCAL',
@name = N'[Uncategorized (Local)]';
Expand All @@ -62,7 +62,7 @@ BEGIN
END;


EXEC @ReturnCode = msdb.dbo.sp_add_job
EXECUTE @ReturnCode = msdb.dbo.sp_add_job
@job_name = N'Clear Security Cache Every 30 Minutes',
@enabled = 1,
@notify_level_eventlog = 0,
Expand All @@ -85,7 +85,7 @@ https://github.com/erikdarlingdata/DarlingData',
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_add_jobstep
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep
@job_id = @jobId,
@step_name = N'Execute dbo.ClearTokenPerm',
@step_id = 1,
Expand All @@ -98,22 +98,22 @@ EXEC @ReturnCode = msdb.dbo.sp_add_jobstep
@retry_interval = 0,
@os_run_priority = 0,
@subsystem = N'TSQL',
@command = N'EXEC dbo.ClearTokenPerm
@command = N'EXECUTE dbo.ClearTokenPerm
@CacheSizeGB = 1;',
@database_name = N'master',
@flags = 0;

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_update_job
EXECUTE @ReturnCode = msdb.dbo.sp_update_job
@job_id = @jobId,
@start_step_id = 1;

IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule
@job_id = @jobId,
@name = N'Clear Security Cache Every 30 Minutes',
@enabled = 1,
Expand All @@ -132,7 +132,7 @@ EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule
IF (@@ERROR <> 0 OR @ReturnCode <> 0)
GOTO QuitWithRollback;

EXEC @ReturnCode = msdb.dbo.sp_add_jobserver
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver
@job_id =
@jobId,
@server_name = N'(local)';
Expand Down
18 changes: 9 additions & 9 deletions Clear Token Perm/ClearTokenPerm.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For background on why you might need this:
In short, if your security caches are growing out of control, it can cause all sorts of weird issues with SQL Server.
Copyright 2024 Darling Data, LLC
Copyright 2025 Darling Data, LLC
https://www.erikdarling.com/
For support, head over to GitHub:
Expand Down Expand Up @@ -48,7 +48,7 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
DECLARE
@clear_triggered bit = 0;

IF OBJECT_ID(N'dbo.ClearTokenPermLogging') IS NULL
IF OBJECT_ID(N'dbo.ClearTokenPermLogging', N'U') IS NULL
BEGIN
CREATE TABLE
dbo.ClearTokenPermLogging
Expand All @@ -70,8 +70,8 @@ IF
(domc.pages_kb / 1024. / 1024.)
)
FROM sys.dm_os_memory_clerks AS domc
WHERE domc.type = 'USERSTORE_TOKENPERM'
AND domc.name = 'TokenAndPermUserStore'
WHERE domc.type = N'USERSTORE_TOKENPERM'
AND domc.name = N'TokenAndPermUserStore'
) >= @CacheSizeGB
BEGIN
INSERT
Expand All @@ -93,8 +93,8 @@ BEGIN
clear_triggered =
1
FROM sys.dm_os_memory_clerks AS domc
WHERE domc.type = 'USERSTORE_TOKENPERM'
AND domc.name = 'TokenAndPermUserStore';
WHERE domc.type = N'USERSTORE_TOKENPERM'
AND domc.name = N'TokenAndPermUserStore';

DBCC FREESYSTEMCACHE('TokenAndPermUserStore');
END;
Expand All @@ -119,14 +119,14 @@ BEGIN
clear_triggered =
0
FROM sys.dm_os_memory_clerks AS domc
WHERE domc.type = 'USERSTORE_TOKENPERM'
AND domc.name = 'TokenAndPermUserStore';
WHERE domc.type = N'USERSTORE_TOKENPERM'
AND domc.name = N'TokenAndPermUserStore';
END;
END;
RETURN;

/*Example execution*/
EXEC dbo.ClearTokenPerm
EXECUTE dbo.ClearTokenPerm
@CacheSizeGB = 1;

/*Query a log*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ https://github.com/erikdarlingdata/DarlingData
MIT License
Copyright 2024 Darling Data, LLC
Copyright 2025 Darling Data, LLC
https://www.erikdarling.com/
Expand Down Expand Up @@ -71,7 +71,7 @@ END;

WHILE @counter < 50000
BEGIN
EXEC sys.sp_setapprole
EXECUTE sys.sp_setapprole
@rolename = N'your_terrible_app',
@password = N'y0ur_t3rr1bl3_4pp',
@fCreateCookie = true,
Expand All @@ -80,7 +80,7 @@ BEGIN
SELECT
@bl0b_eater = USER_NAME();

EXEC sys.sp_unsetapprole
EXECUTE sys.sp_unsetapprole
@cronut;

SELECT
Expand Down Expand Up @@ -174,9 +174,9 @@ SELECT
token_name =
c.c.value('@name', 'varchar(50)'),
principal_id =
c.c.value('@id', 'int'),
c.c.value('@id', 'integer'),
database_id =
c.c.value('@dbid', 'int'),
c.c.value('@dbid', 'integer'),
time_stamp =
c.c.value('@timestamp', 'bigint')
INTO #tapus
Expand Down Expand Up @@ -204,7 +204,7 @@ SELECT
FROM #tapus AS t
INNER JOIN sys.server_principals AS p
ON t.principal_id = p.principal_id
WHERE t.token_name = 'SecContextToken'
WHERE t.token_name = N'SecContextToken'
GROUP BY
p.name
ORDER BY
Expand All @@ -219,8 +219,8 @@ SELECT
FROM #tapus AS t
INNER JOIN sys.databases AS d
ON d.database_id = t.database_id
WHERE t.token_name = 'UserToken'
AND t.cache_name = 'TokenAndPermUserStore'
WHERE t.token_name = N'UserToken'
AND t.cache_name = N'TokenAndPermUserStore'
GROUP BY
d.name
ORDER BY
Expand All @@ -235,7 +235,7 @@ SELECT
FROM #tapus AS t
INNER JOIN sys.databases AS d
ON d.database_id = t.database_id
WHERE t.token_name = 'UserToken'
WHERE t.token_name = N'UserToken'
GROUP BY
d.name
ORDER BY
Expand Down
2 changes: 1 addition & 1 deletion Create Long IN List/Longingly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GO
This procedure exists only to show how long IN clauses can hurt query performance.
Copyright 2024 Darling Data, LLC
Copyright 2025 Darling Data, LLC
https://www.erikdarling.com/
For support, head over to GitHub:
Expand Down
4 changes: 2 additions & 2 deletions Dynamic SQL Logging/Dynamic SQL Logging.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GO
Stored procedure to be used for logging performance information from dynamic SQL
Copyright (c) 2024 Darling Data, LLC
Copyright (c) 2025 Darling Data, LLC
https://www.erikdarling.com/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
Expand All @@ -32,7 +32,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
CREATE OR ALTER PROCEDURE
dbo.logging
(
@spid int,
@spid integer,
@sql nvarchar(MAX),
@query_plan xml,
@guid_in uniqueidentifier,
Expand Down
Loading

0 comments on commit 31aa63c

Please sign in to comment.