经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库运维 » MS SQL Server » 查看文章
How to monitor tempdb in MS SQL
来源:cnblogs  作者:vicent_199077  时间:2018/10/18 8:54:07  对本文有异议

Error: tempdb is full due to active_transaction.

 

  1. 1 select
  2. 2 ss.[host_name],
  3. 3 ss.login_name,
  4. 4 ss.original_login_name,
  5. 5 ss.[status],
  6. 6 R.*
  7. 7 from(
  8. 8 SELECT COALESCE(T1.session_id, T2.session_id) [session_id] ,
  9. 9 T1.request_id ,
  10. 10 COALESCE(T1.database_id, T2.database_id) [database_id],
  11. 11 DB_NAME(COALESCE(T1.database_id, T2.database_id)) as Database_Name,
  12. 12 COALESCE(T1.[Total Allocation User Objects], 0) + T2.[Total Allocation User Objects] [Total Allocation User Objects (MB)] ,
  13. 13 COALESCE(T1.[Net Allocation User Objects], 0) + T2.[Net Allocation User Objects] [Net Allocation User Objects] ,
  14. 14 COALESCE(T1.[Total Allocation Internal Objects], 0) + T2.[Total Allocation Internal Objects] [Total Allocation Internal Objects (MB)] ,
  15. 15 COALESCE(T1.[Net Allocation Internal Objects], 0) + T2.[Net Allocation Internal Objects] [Net Allocation Internal Objects (MB)] ,
  16. 16 COALESCE(T1.[Total Allocation], 0) + T2.[Total Allocation] [Total Allocation (MB)] ,
  17. 17 COALESCE(T1.[Net Allocation], 0) + T2.[Net Allocation] [Net Allocation (MB)] ,
  18. 18 COALESCE(T1.[Query Text], T2.[Query Text]) [Query Text]
  19. 19 FROM (( SELECT TS.session_id,
  20. 20 TS.request_id,
  21. 21 TS.database_id,
  22. 22 CAST(TS.user_objects_alloc_page_count / 128. AS DECIMAL(15,2)) [Total Allocation User Objects] ,
  23. 23 CAST((TS.user_objects_alloc_page_count - TS.user_objects_dealloc_page_count) / 128. AS DECIMAL(15,2)) [Net Allocation User Objects] ,
  24. 24 CAST(TS.internal_objects_alloc_page_count / 128. AS DECIMAL(15,2)) [Total Allocation Internal Objects] ,
  25. 25 CAST((TS.internal_objects_alloc_page_count - TS.internal_objects_dealloc_page_count) / 128. AS DECIMAL(15,2)) [Net Allocation Internal Objects] ,
  26. 26 CAST((TS.user_objects_alloc_page_count + internal_objects_alloc_page_count) / 128. AS DECIMAL(15,2)) [Total Allocation] ,
  27. 27 CAST((TS.user_objects_alloc_page_count + TS.internal_objects_alloc_page_count - TS.internal_objects_dealloc_page_count - TS.user_objects_dealloc_page_count) / 128. AS DECIMAL(15,2)) [Net Allocation] ,
  28. 28 T.text [Query Text]
  29. 29 FROM sys.dm_db_task_space_usage TS
  30. 30 INNER JOIN sys.dm_exec_requests ER ON ER.request_id = TS.request_id AND ER.session_id = TS.session_id
  31. 31 OUTER APPLY sys.dm_exec_sql_text(ER.sql_handle) T
  32. 32 ) T1
  33. 33 RIGHT JOIN
  34. 34 ( SELECT SS.session_id,
  35. 35 SS.database_id,
  36. 36 CAST(SS.user_objects_alloc_page_count / 128. AS DECIMAL(15,2)) [Total Allocation User Objects] ,
  37. 37 CAST((SS.user_objects_alloc_page_count - SS.user_objects_dealloc_page_count)/ 128. AS DECIMAL(15, 2)) [Net Allocation User Objects] ,
  38. 38 CAST(SS.internal_objects_alloc_page_count / 128. AS DECIMAL(15,2)) [Total Allocation Internal Objects] ,
  39. 39 CAST((SS.internal_objects_alloc_page_count - SS.internal_objects_dealloc_page_count) / 128. AS DECIMAL(15, 2)) [Net Allocation Internal Objects] ,
  40. 40 CAST((SS.user_objects_alloc_page_count + internal_objects_alloc_page_count) / 128. AS DECIMAL(15, 2)) [Total Allocation] ,
  41. 41 CAST((SS.user_objects_alloc_page_count + SS.internal_objects_alloc_page_count - SS.internal_objects_dealloc_page_count - SS.user_objects_dealloc_page_count) / 128. AS DECIMAL(15, 2)) [Net Allocation] ,
  42. 42 T.text [Query Text]
  43. 43 FROM sys.dm_db_session_space_usage SS
  44. 44 LEFT JOIN sys.dm_exec_connections CN ON CN.session_id = SS.session_id
  45. 45 OUTER APPLY sys.dm_exec_sql_text(CN.most_recent_sql_handle) T
  46. 46 ) T2 ON T1.session_id = T2.session_id)
  47. 47 ) R
  48. 48 left join sys.dm_exec_sessions ss on R.session_id=ss.session_id
  49. 49 order by ss.status, [Total Allocation User Objects (MB)] desc

 

 

参考链接:https://www.mssqltips.com/sqlservertip/4356/track-sql-server-tempdb-space-usage/

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号