仅杀死 SQL Server 中的用户进程 [英] Kill only user processes in SQL Server

查看:43
本文介绍了仅杀死 SQL Server 中的用户进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些用户忘记关闭使用我们的 SQL 2014 数据库的访问查询.当这种情况发生时,它会阻止他们正在访问的表在夜间重建.有什么办法可以杀死这些用户而不是杀死系统进程.据我所知,系统进程不仅限于 SPID > 50.

We have users that forget to close their access queries that use our SQL 2014 databases. When this happens it prevents the tables they are accessing from being rebuilt over night. Is there any way to Kill these users and not kill the system processes. From what I've read system processes are not only limited to SPID >50.

推荐答案

基于 spid>=50 杀死用户进程似乎不可靠.

Killing user processes based on spid>=50 seems to be not reliable.

来自 Adam Machanic:粉碎 DMV 神话:session_id> 50 == 用户进程

From Adam Machanic:Smashing a DMV Myth: session_id > 50 == User Process

最近在 MVP 邮件列表上的一个对话显示,这个神奇的数字,虽然可能曾经是一个合法的过滤器,但在 SQL Server 2005 或 SQL Server 2008 中使用肯定是不安全的.一些系统功能可以——也将会——使用会话 ID 大于 50,因为否则根本没有足够的空间.

A recent conversation on an MVP mailing list revealed that this magic number, while perhaps once a legitimate filter, is certainly not safe to use in SQL Server 2005 or SQL Server 2008. Several system features can--and will--use session IDs greater than 50, because there is simply not enough room otherwise.

示例包括:

  • 使用软 NUMA 的大型服务器,因为每个 NUMA 节点有一个检查点和惰性写入器线程
  • 异步统计更新,再次(尤其是)在较大的服务器上
    数据库镜像,尤其是在涉及大量数据库的情况下
  • Service Broker 激活,当使用大量激活任务时

可能还有其他情况.关键是,数字 50 不再是过滤掉系统会话 ID 的有效方法.

所以你的选择是

SELECT *
FROM sys.dm_exec_sessions
WHERE
    is_user_process = 1

SELECT *
FROM sys.sysprocesses
WHERE
    hostprocess > ''

您可以使用上述查询来获取系统以外的 spids/session 并使用 kill 命令杀死它们

You can use above queries to get spids/session other than system and use kill command to kill them

这篇关于仅杀死 SQL Server 中的用户进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆