SQL SERVER 事务执行情况跟踪分析
[sql] view plain copy
---查看现在所有的事务 select '正在运行事务的会话的 ID'=session_id, --session_id与transaction_id的对应关系
'事务的 ID'=transaction_id,
'正在处理事务的会话中的活动请求数'=enlist_count,
'用户or系统事务'=case is_user_transaction when 1 then '事务由用户请求启动'
when 0 then '系统事务'
end,
'本地or分布式事务'= case is_local when 0 then '分布式事务或登记的绑定会话事务'
when 1 then '本地事务'
end,
'分布式事务类型'=case is_enlisted when 0 then '非登记的分布式事务'
when 1 then '登记的分布式事务'
end,
'绑定会话中处于状态'=case is_enlisted when 0 then '事务在通过绑定会话的会话中处于非活动状态。'
when 1 then '事务在通过绑定会话的会话中处于活动状态'
end
from sys.dm_tran_session_transactions --会话中的事务,识别所有打开的事务
where is_user_transaction =1 ----活动事务的具体信息
select dt.transaction_id,
dt.name,
dt.transaction_begin_time,
case dt.transaction_type
when 1 then '读/写事务'
when 2 then '只读事务'
when 3 then '系统事务'
when 4 then '分布式事务'
end 'transaction type', case dt.transaction_state
when 0 then '事务尚未完全初始化'
when 1 then '事务已初始化但尚未启动'
when 2 then '事务处于活动状态'
when 3 then '事务已结束。该状态用于只读事务'
when 4 then '已对分布式事务启动提交进程'
when 5 then '事务处于准备就绪状态且等待解析'
when 6 then '事务已提交'
when 7 then '事务正在被回滚'
when 8 then '事务已回滚'
end 'transaction state',
case dt.dtc_state
when 1 then '活动'
when 2 then '准备就绪'
when 3 then '已提交'
when 4 then '中止'
when 5 then '已恢复'
end dtc_state from sys.dm_tran_active_transactions dt --活动的事务
where transaction_id = 123 ---根据事务ID 和其对应的session_id 找到活动事务对应的执行语句 select dc.session_id,
ds.login_name,
ds.login_time,
dc.connect_time,
dc.client_net_address,
ds.host_name,
ds.program_name,
case ds.status when 'sleeping' then '睡眠 - 当前没有运行任何请求 '
when 'running' then '正在运行 - 当前正在运行一个或多个请求 '
when 'Dormancy' then '休眠 – 会话因连接池而被重置,并且现在处于登录前状态'
when 'Pre-connected' then '预连接 - 会话在资源调控器分类器中'
end as status ,
ds.cpu_time as cpu_time_ms,
ds.memory_usage*8 as memory_kb,
ds.total_elapsed_time as total_elapsed_time_ms,
case ds.transaction_isolation_level when 0 then '未指定'
when 1 then '未提交读取'
when 2 then '已提交读取'
when 3 then '可重复'
when 4 then '可序列化'
when 5 then '快照'
end '会话的事务隔离级别',
dt.text
from sys.dm_exec_connections dc --执行连接,最近执行的查询信息
cross apply sys.dm_exec_sql_text(dc.most_recent_sql_handle) dt
join sys.dm_exec_sessions ds on dc.session_id=ds.session_id
where dc.session_id = 55
- ---查看现在所有的事务
- select '正在运行事务的会话的 ID'=session_id, --session_id与transaction_id的对应关系
- '事务的 ID'=transaction_id,
- '正在处理事务的会话中的活动请求数'=enlist_count,
- '用户or系统事务'=case is_user_transaction when 1 then '事务由用户请求启动'
- when 0 then '系统事务'
- end,
- '本地or分布式事务'= case is_local when 0 then '分布式事务或登记的绑定会话事务'
- when 1 then '本地事务'
- end,
- '分布式事务类型'=case is_enlisted when 0 then '非登记的分布式事务'
- when 1 then '登记的分布式事务'
- end,
- '绑定会话中处于状态'=case is_enlisted when 0 then '事务在通过绑定会话的会话中处于非活动状态。'
- when 1 then '事务在通过绑定会话的会话中处于活动状态'
- end
- from sys.dm_tran_session_transactions --会话中的事务,识别所有打开的事务
- where is_user_transaction =1
- ----活动事务的具体信息
- select dt.transaction_id,
- dt.name,
- dt.transaction_begin_time,
- case dt.transaction_type
- when 1 then '读/写事务'
- when 2 then '只读事务'
- when 3 then '系统事务'
- when 4 then '分布式事务'
- end 'transaction type',
- case dt.transaction_state
- when 0 then '事务尚未完全初始化'
- when 1 then '事务已初始化但尚未启动'
- when 2 then '事务处于活动状态'
- when 3 then '事务已结束。该状态用于只读事务'
- when 4 then '已对分布式事务启动提交进程'
- when 5 then '事务处于准备就绪状态且等待解析'
- when 6 then '事务已提交'
- when 7 then '事务正在被回滚'
- when 8 then '事务已回滚'
- end 'transaction state',
- case dt.dtc_state
- when 1 then '活动'
- when 2 then '准备就绪'
- when 3 then '已提交'
- when 4 then '中止'
- when 5 then '已恢复'
- end dtc_state
- from sys.dm_tran_active_transactions dt --活动的事务
- where transaction_id = 123
- ---根据事务ID 和其对应的session_id 找到活动事务对应的执行语句
- select dc.session_id,
- ds.login_name,
- ds.login_time,
- dc.connect_time,
- dc.client_net_address,
- ds.host_name,
- ds.program_name,
- case ds.status when 'sleeping' then '睡眠 - 当前没有运行任何请求 '
- when 'running' then '正在运行 - 当前正在运行一个或多个请求 '
- when 'Dormancy' then '休眠 – 会话因连接池而被重置,并且现在处于登录前状态'
- when 'Pre-connected' then '预连接 - 会话在资源调控器分类器中'
- end as status ,
- ds.cpu_time as cpu_time_ms,
- ds.memory_usage*8 as memory_kb,
- ds.total_elapsed_time as total_elapsed_time_ms,
- case ds.transaction_isolation_level when 0 then '未指定'
- when 1 then '未提交读取'
- when 2 then '已提交读取'
- when 3 then '可重复'
- when 4 then '可序列化'
- when 5 then '快照'
- end '会话的事务隔离级别',
- dt.text
- from sys.dm_exec_connections dc --执行连接,最近执行的查询信息
- cross apply sys.dm_exec_sql_text(dc.most_recent_sql_handle) dt
- join sys.dm_exec_sessions ds on dc.session_id=ds.session_id
- where dc.session_id = 55

SQL SERVER 事务执行情况跟踪分析的更多相关文章
- 监控SQL Server正在执行的SQL语句和死锁情况
原文:监控SQL Server正在执行的SQL语句和死锁情况 SELECT [Individual Query] = SUBSTRING(qt.TEXT, er.statement_start_off ...
- SQL Server事务详解
事务定义: 事务是单个的工作单元.如果某一事务成功,则在该事务中进行的所有数据更改均会提交,成为数据库中的永久组成部分.如果事务遇到错误且必须取消或回滚,则所有数据更改均被清除. 事务三种运行模式: ...
- SQL Server 事务复制爬坑记
SQL Server 复制功能折腾了好几天了,现特将其配置过程以及其间遇到的问题记录下来,以备日后查阅.同时,也让“同道”同学们少走不必要的弯路.如果有不对之处,欢迎大家指正,欢迎沟通交流. 一.复制 ...
- 网络异常与SQL Server事务
SQL Server事务遭遇网络异常时的处理机制浅析 SQL Server数据库中,如果应用程序正在执行一个事务的时候突然遭遇了网络异常,例如网络掉包,网络中断等,那么这个事务会怎么样? SQL Se ...
- SQL Server 事务复制分发到订阅同步慢
原文:SQL Server 事务复制分发到订阅同步慢 最近发现有一个发布经常出现问题,每几天就出错不同步,提示要求初始化.重新调整同步后,复制还是很慢!每天白天未分发的命令就达五六百万条!要解决慢的问 ...
- SQL Server 优化-执行计划
对于SQL Server的优化来说,优化查询可能是很常见的事情.由于数据库的优化,本身也是一个涉及面比较的广的话题, 因此本文只谈优化查询时如何看懂SQL Server查询计划.毕竟我对SQL Ser ...
- 人人都是 DBA(VI)SQL Server 事务日志
SQL Server 的数据库引擎通过事务服务(Transaction Services)提供事务的 ACID 属性支持.ACID 属性包括: 原子性(Atomicity) 一致性(Consisten ...
- 第1/24周 SQL Server 如何执行一个查询
大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Server如何执行一个查询来建立基础.这个部分非常重要, ...
- 了解Sql Server的执行计划
前一篇总结了Sql Server Profiler,它主要用来监控数据库,并跟踪生成的sql语句.但是只拿到生成的sql语句没有什么用,我们可以利用这些sql语句,然后结合执行计划来分析sql语句的性 ...
随机推荐
- Python迭代器笔记
python中的三大器有迭代器,生成器,装饰器,本文重点讲解下迭代器的概念,使用,自定义迭代器等的介绍. 1.概念: 迭代器是一个对象,一个可以记住遍历位置的对象,迭代器对象从集合的第一个元素开始访问 ...
- C++ template —— 模板与继承(八)
16.1 命名模板参数许多模板技术往往让类模板拖着一长串类型参数:不过许多参数都设有合理的缺省值,如: template <typename policy1 = DefaultPolicy1, ...
- 【LeetCode OJ】Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...
- Android 自定义 View 浅析
Android 自定义 View 浅析 概括 说到自定义 View ,就一定得说说 android 系统的UI绘制流程.再说这个流程之前,我们先看一下在每一个 activity 页面中我们的布局 ui ...
- css !important用法以及CSS样式使用优先级判断
之前一直看到很多css中都有!important这个样式,一直不知道有什么作用的,今天在网上详细了解了一下,看了别人的博客,顺便转载收藏一下 css !important用法CSS样式使用优先级判断 ...
- 多了解一下Chrome开发者控制台
多了解一下Chrome开发者控制台 2017年10月14日 • Tools, Web前端 • 1.0k views • 暂无评论 作为一名前端开发者,Chrome内置的控制台是必须了解的,它拥有非常丰 ...
- No.1 PyQt学习
由于项目的原因,要学PyQt了.以下是第一天的学习成果 # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui, QtCore class ...
- 关于 CommonJS AMD CMD UMD 规范的差异总结(转)
根据CommonJS规范,一个单独的文件就是一个模块.每一个模块都是一个单独的作用域,也就是说,在一个文件定义的变量(还包括函数和类),都是私有的,对其他文件是不可见的. // foo.js var ...
- gradle-4.1-all.zip
1. https://services.gradle.org/distributions/ https://services.gradle.org/distributions/gradle-4.1-a ...
- GoldenGate的监控
1.进入GoldenGate安装目录,运行GGSCI,然后使用info all查看整体的运行状况 GGSCI (aix212) 1> info all Program Status Group ...