SQL Server System Session ID是不是1-50?

简介:

今天在论坛看到一篇文章问到为什么SQL Server系统的SESSION ID是从1到50的,以前看过文章,这些Session是SQL Server为了运行系统活动比如((lazy writer, ghost record cleanup, DTC commit/abort),所以会保留50 Session ID给SQL Server使用,用户会话从51开始。

 

在2005之前查询用户会话使用:

 

 

select * from sysprocesses wherespid < 50

 

但是在SQL Server 2005之后已经没有这个限制了,我在MSDN上找到了下面这篇文章:How It Works: System Sessions

 

Looking at a SQL Server error log it is formatted with the datetime and session identifier. Many of the identifiers contain the s following the spid value.

2008-01-08 20:03:36.12 spid5s

The indicates that the session is a system session. Prior to SQL Server 2005 all system sessions were limited to session ids less than 50. SQL Server 2005 lifted that restriction. In order identify a session performing system actives (lazy writer, ghost record cleanup, DTC commit/abort, ...) the sessions are identified as system sessions.

Instead of the older "select * from sysprocesses where spid < 50" you should use "select * from sys.dm_exec_sessions where is_user_process = 0" to identify system processes.

 

根据上面的讲法系统Session ID有可能超过50,所以查询用户Session ID使用

 

select * from sys.dm_exec_sessionswhereis_user_process= 1

 

is_user_process

bit

如果会话是系统会话,则为 0。否则,为 1。不可为空值

 

更多信息参考:http://msdn.microsoft.com/zh-cn/library/ms176013(v=sql.90).aspx


本文转自 lzf328 51CTO博客,原文链接:

http://blog.51cto.com/lzf328/1021521
相关文章
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
563 13
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
379 9
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
274 6
|
SQL 安全 网络安全
Hospital Management System v4.0 SQL 注入(CVE-2022-24263)
Hospital Management System v4.0 SQL 注入(CVE-2022-24263)
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
1211 3
|
存储 SQL C++
对比 SQL Server中的VARCHAR(max) 与VARCHAR(n) 数据类型
【7月更文挑战7天】SQL Server 中的 VARCHAR(max) vs VARCHAR(n): - VARCHAR(n) 存储最多 n 个字符(1-8000),适合短文本。 - VARCHAR(max) 可存储约 21 亿个字符,适合大量文本。 - VARCHAR(n) 在处理小数据时性能更好,空间固定。 - VARCHAR(max) 对于大文本更合适,但可能影响性能。 - 选择取决于数据长度预期和业务需求。
1201 1
|
SQL 存储 安全
数据库数据恢复—SQL Server数据库出现逻辑错误的数据恢复案例
SQL Server数据库数据恢复环境: 某品牌服务器存储中有两组raid5磁盘阵列。操作系统层面跑着SQL Server数据库,SQL Server数据库存放在D盘分区中。 SQL Server数据库故障: 存放SQL Server数据库的D盘分区容量不足,管理员在E盘中生成了一个.ndf的文件并且将数据库路径指向E盘继续使用。数据库继续运行一段时间后出现故障并报错,连接失效,SqlServer数据库无法附加查询。管理员多次尝试恢复数据库数据但是没有成功。
|
SQL 存储 测试技术
|
SQL 存储 关系型数据库
关系型数据库SQL Server学习
【7月更文挑战第4天】
241 2