Skip to content

Commit befc0d3

Browse files
BrentOzarclaude
andcommitted
sp_kill: remove targeting filter safety check
Allow @ExecuteKills = 'Y' with no filters to kill all user sessions except the caller's own SPID. The no-filter guard in the recommendation logic now only applies in display mode (@ExecuteKills = 'N'). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2ecf122 commit befc0d3

1 file changed

Lines changed: 5 additions & 32 deletions

File tree

sp_kill.sql

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ BEGIN
4848
versions for free, watch training videos on how it works, get more info on
4949
the findings, contribute your own code, and more.
5050
51-
Known limitations of this version:
52-
- Only Microsoft-supported versions of SQL Server (2016+).
53-
- Does not kill system sessions (session_id <= 50).
54-
- Does not kill sessions that are already rolling back.
55-
56-
Unknown limitations of this version:
57-
- None. (If we knew them, they would be known. Duh.)
58-
5951
MIT License
6052
6153
Copyright (c) Brent Ozar Unlimited
@@ -267,25 +259,6 @@ For more info, visit http://FirstResponderKit.org
267259
RETURN;
268260
END;
269261

270-
/* Safety check: require at least one inclusive targeting filter when ExecuteKills = Y.
271-
@OmitLogin is excluded from this check because it's an exclusion filter -
272-
using only @OmitLogin would kill nearly everything except that login. */
273-
IF @ExecuteKills = 'Y'
274-
AND @SPID IS NULL
275-
AND @LoginName IS NULL
276-
AND @AppName IS NULL
277-
AND @DatabaseName IS NULL
278-
AND @HostName IS NULL
279-
AND @LeadBlockers = 'N'
280-
AND @ReadOnly = 'N'
281-
AND @SPIDState = ''
282-
AND @HasOpenTran = ''
283-
AND @RequestsOlderThanMinutes IS NULL
284-
BEGIN
285-
RAISERROR('You must specify at least one targeting filter when @ExecuteKills = ''Y''. Otherwise we might kill everything.', 11, 1) WITH NOWAIT;
286-
RETURN;
287-
END;
288-
289262
/*-------------------------------------------------------
290263
Section 4: Output Table Name Sanitization
291264
-------------------------------------------------------*/
@@ -630,10 +603,11 @@ For more info, visit http://FirstResponderKit.org
630603
AND login_name = @OmitLogin;
631604
END;
632605

633-
/* If no targeting filters were set and @ExecuteKills = 'N', keep recommendations
634-
but clear KillCommand for sessions that don't look problematic.
635-
If @ExecuteKills = 'Y', the safety check in Section 3 already prevented this. */
636-
IF @LoginName IS NULL
606+
/* If no targeting filters were set and @ExecuteKills = 'N', don't recommend
607+
killing anything - just show all sessions. When @ExecuteKills = 'Y',
608+
no filters means kill everything (except our own session). */
609+
IF @ExecuteKills = 'N'
610+
AND @LoginName IS NULL
637611
AND @AppName IS NULL
638612
AND @DatabaseName IS NULL
639613
AND @HostName IS NULL
@@ -644,7 +618,6 @@ For more info, visit http://FirstResponderKit.org
644618
AND @RequestsOlderThanMinutes IS NULL
645619
AND @OmitLogin = ''
646620
BEGIN
647-
/* No filters at all - don't recommend killing anything */
648621
UPDATE #sp_kill_sessions
649622
SET KillRecommended = 0,
650623
Reason = NULL

0 commit comments

Comments
 (0)