Skip to content

Commit 8795706

Browse files
BrentOzarclaude
andcommitted
sp_kill: rename @RequestsOlderThanMinutes to @RequestsOlderThanSeconds
Seconds granularity is more useful in production emergencies where you may need to kill all queries running longer than e.g. 10 seconds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8370607 commit 8795706

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

sp_kill.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ALTER PROCEDURE dbo.sp_kill
1515
@SPIDState VARCHAR(1) = NULL,
1616
@OmitLogin NVARCHAR(256) = NULL,
1717
@HasOpenTran VARCHAR(1) = NULL,
18-
@RequestsOlderThanMinutes INT = NULL,
18+
@RequestsOlderThanSeconds INT = NULL,
1919
@OutputDatabaseName NVARCHAR(256) = NULL,
2020
@OutputSchemaName NVARCHAR(256) = NULL,
2121
@OutputTableName NVARCHAR(256) = NULL,
@@ -127,8 +127,8 @@ Parameters:
127127
@HasOpenTran VARCHAR(1) = NULL
128128
Y = only target sessions with open transactions.
129129
130-
@RequestsOlderThanMinutes INT = NULL
131-
Only target sessions whose last request started at least this many minutes ago.
130+
@RequestsOlderThanSeconds INT = NULL
131+
Only target sessions whose last request started at least this many seconds ago.
132132
133133
@OutputDatabaseName, @OutputSchemaName, @OutputTableName
134134
Optional 3-part name for persistent logging table.
@@ -152,9 +152,9 @@ Example usage:
152152
-- Kill a specific session:
153153
EXEC sp_kill @SPID = 55, @ExecuteKills = ''Y'';
154154
155-
-- Kill sleeping sessions with open transactions older than 5 minutes:
155+
-- Kill sleeping sessions with open transactions older than 10 seconds:
156156
EXEC sp_kill @HasOpenTran = ''Y'', @SPIDState = ''S'',
157-
@RequestsOlderThanMinutes = 5, @ExecuteKills = ''Y'';
157+
@RequestsOlderThanSeconds = 10, @ExecuteKills = ''Y'';
158158
159159
-- Just show what we would kill for a specific login, sorted by CPU:
160160
EXEC sp_kill @LoginName = ''DOMAIN\TroublesomeUser'', @OrderBy = ''cpu'';
@@ -214,7 +214,7 @@ For more info, visit http://FirstResponderKit.org
214214
IF @SPIDState IS NOT NULL SET @ParametersUsed = @ParametersUsed + N', @SPIDState = ''' + REPLACE(@SPIDState, N'''', N'''''') + N'''';
215215
IF @OmitLogin IS NOT NULL SET @ParametersUsed = @ParametersUsed + N', @OmitLogin = N''' + REPLACE(@OmitLogin, N'''', N'''''') + N'''';
216216
IF @HasOpenTran IS NOT NULL SET @ParametersUsed = @ParametersUsed + N', @HasOpenTran = ''' + REPLACE(@HasOpenTran, N'''', N'''''') + N'''';
217-
IF @RequestsOlderThanMinutes IS NOT NULL SET @ParametersUsed = @ParametersUsed + N', @RequestsOlderThanMinutes = ' + CAST(@RequestsOlderThanMinutes AS NVARCHAR(10));
217+
IF @RequestsOlderThanSeconds IS NOT NULL SET @ParametersUsed = @ParametersUsed + N', @RequestsOlderThanSeconds = ' + CAST(@RequestsOlderThanSeconds AS NVARCHAR(10));
218218

219219
/*-------------------------------------------------------
220220
Section 3: Parameter Validation
@@ -249,9 +249,9 @@ For more info, visit http://FirstResponderKit.org
249249
RETURN;
250250
END;
251251

252-
IF @RequestsOlderThanMinutes IS NOT NULL AND @RequestsOlderThanMinutes < 0
252+
IF @RequestsOlderThanSeconds IS NOT NULL AND @RequestsOlderThanSeconds < 0
253253
BEGIN
254-
RAISERROR('@RequestsOlderThanMinutes must be >= 0.', 11, 1) WITH NOWAIT;
254+
RAISERROR('@RequestsOlderThanSeconds must be >= 0.', 11, 1) WITH NOWAIT;
255255
RETURN;
256256
END;
257257

@@ -508,7 +508,7 @@ For more info, visit http://FirstResponderKit.org
508508
AND @ReadOnly IS NULL
509509
AND @SPIDState IS NULL
510510
AND @HasOpenTran IS NULL
511-
AND @RequestsOlderThanMinutes IS NULL
511+
AND @RequestsOlderThanSeconds IS NULL
512512
AND @OmitLogin IS NULL
513513
BEGIN
514514
/* No filters in display mode - nothing to recommend */
@@ -529,7 +529,7 @@ For more info, visit http://FirstResponderKit.org
529529
AND (@ReadOnly IS NULL OR is_read_only = 1)
530530
AND (@SPIDState IS NULL OR (@SPIDState = 'S' AND [status] = 'sleeping') OR (@SPIDState = 'R' AND [status] = 'running'))
531531
AND (@HasOpenTran IS NULL OR ISNULL(open_transaction_count, 0) > 0)
532-
AND (@RequestsOlderThanMinutes IS NULL OR last_request_start_time <= DATEADD(MINUTE, -@RequestsOlderThanMinutes, GETDATE()))
532+
AND (@RequestsOlderThanSeconds IS NULL OR last_request_start_time <= DATEADD(SECOND, -@RequestsOlderThanSeconds, GETDATE()))
533533
AND (@OmitLogin IS NULL OR login_name <> @OmitLogin)
534534
AND (@LeadBlockers IS NULL OR (
535535
EXISTS (SELECT 1 FROM #hitlist blocked WHERE blocked.blocking_session_id = h.session_id)

0 commit comments

Comments
 (0)