查看temp db

发布时间:2020-08-08 10:00:27 作者:o0yuki0o
来源:ITPUB博客 阅读:161
use tempdb                                                               


-- 每隔1秒钟运行一次,直到用户手工终止脚本运行


while 1=1                                                               


begin                                                                   


select getdate()                                                        


-- 从文件级看tempdb使用情况


dbcc showfilestats                                                      


-- Query 1


-- 返回所有做过空间申请的session信息


Select 'Tempdb' as DB, getdate() as Time,                                                        


    SUM (user_object_reserved_page_count)*8 as user_objects_kb,         


    SUM (internal_object_reserved_page_count)*8 as internal_objects_kb, 


    SUM (version_store_reserved_page_count)*8  as version_store_kb,     


    SUM (unallocated_extent_page_count)*8 as freespace_kb               


From sys.dm_db_file_space_usage                                         


Where database_id = 2                                                    


-- Query 2


-- 这个管理视图能够反映当时tempdb空间的总体分配


SELECT t1.session_id,                                                   


t1.internal_objects_alloc_page_count,  t1.user_objects_alloc_page_count,


t1.internal_objects_dealloc_page_count , t1.user_objects_dealloc_page_count,


t3.*


from sys.dm_db_session_space_usage  t1 ,                               


-- 反映每个session累计空间申请


sys.dm_exec_sessions as t3


-- 每个session的信息


where


t1.session_id = t3.session_id


and (t1.internal_objects_alloc_page_count>0


or t1.user_objects_alloc_page_count >0


or t1.internal_objects_dealloc_page_count>0


or t1.user_objects_dealloc_page_count>0)


-- Query 3


-- 返回正在运行并且做过空间申请的session正在运行的语句


SELECT t1.session_id,                                                    


st.text                                                        


from sys.dm_db_session_space_usage as t1,                               


sys.dm_exec_requests as t4                                              


CROSS APPLY sys.dm_exec_sql_text(t4.sql_handle) AS st                   


 where  t1.session_id = t4.session_id                                       


   and t1.session_id >50                                                


and (t1.internal_objects_alloc_page_count>0


or t1.user_objects_alloc_page_count >0


or t1.internal_objects_dealloc_page_count>0


or t1.user_objects_dealloc_page_count>0)                                              


waitfor delay '0:0:1'                                                    


end          


点击(此处)折叠或打开

  1. select replace(a.hostname,' ','') as hostname ,''''+replace(program_name,' ','')+'''' as program_name
  2. , loginame, j.*
  3. from (
  4. SELECT t1.session_id, t1.internal_objects_alloc_page_count*8.0 internal_objects_alloc_KB,
  5. t1.user_objects_alloc_page_count*8.0 user_objects_alloc_KB,
  6. t1.internal_objects_dealloc_page_count*8.0 internal_objects_dealloc_KB,
  7. t1.user_objects_dealloc_page_count*8.0 user_objects_dealloc_KB,
  8. st.text
  9. from sys.dm_db_session_space_usage as t1,
  10. sys.dm_exec_requests as t4
  11. CROSS APPLY sys.dm_exec_sql_text(t4.sql_handle) AS st
  12. where t1.session_id = t4.session_id
  13.   and t1.session_id >50
  14.   and (t1.internal_objects_alloc_page_count>0
  15.     or t1.user_objects_alloc_page_count >0
  16.     or t1.internal_objects_dealloc_page_count>0
  17.     or t1.user_objects_dealloc_page_count>0) ) as j
  18. left join
  19.     sys.sysprocesses as a with(nolock) on a.spid=j.session_id
  20.     where isnull(a.loginame,'') <>''

点击(此处)折叠或打开

  1. select j.session_id,replace(s.hostname,' ','') as hostname ,''''+replace(s.program_name,' ','')+'''' as program_name
  2. , s.loginame, db_name(s.dbid) AS DBname,j.text from
  3.                                              
  4.  ( SELECT t1.session_id,st.text
  5. from sys.dm_db_session_space_usage as t1,
  6. sys.dm_exec_requests as t4
  7. CROSS APPLY sys.dm_exec_sql_text(t4.sql_handle) AS st
  8.                
  9.  where t1.session_id = t4.session_id
  10.     and t1.session_id >50
  11.     and (t1.internal_objects_alloc_page_count>0
  12.     or t1.user_objects_alloc_page_count >0
  13.     or t1.internal_objects_dealloc_page_count>0
  14.     or t1.user_objects_dealloc_page_count>0)) as j
  15.                                              
  16. left join
  17.     sys.sysprocesses as s with(nolock) on s.spid=j.session_id
  18.         where isnull(s.loginame,'') <>''


点击(此处)折叠或打开

  1. select sum(convert(float,size) * (8192/1024)/1024/1024) TMPFILE_GB, sum(convert(float,maxsize) * (8192/1024)/1024/1024) MAX_TMPFILE_GB,(sum(size)*1.0/sum(maxsize))*100 USED_PER from tempdb.dbo.sysfiles
  2. where name like 'tempdev%'
  3. select * from tempdb.dbo.sysfiles


               

点击(此处)折叠或打开

  1. use tempdb

  2. -- 每隔1秒钟运行一次,直到用户手工终止脚本运行

  3. while 1=1

  4. begin

  5. select getdate()

  6. -- 从文件级看tempdb使用情况

  7. dbcc showfilestats

  8. -- Query 1

  9. -- 返回所有做过空间申请的session信息

  10. Select 'Tempdb' as DB, getdate() as Time,

  11.     SUM (user_object_reserved_page_count)*8 as user_objects_kb,

  12.     SUM (internal_object_reserved_page_count)*8 as internal_objects_kb,

  13.     SUM (version_store_reserved_page_count)*8 as version_store_kb,

  14.     SUM (unallocated_extent_page_count)*8 as freespace_kb

  15. From sys.dm_db_file_space_usage

  16. Where database_id = 2

  17. -- Query 2

  18. -- 这个管理视图能够反映当时tempdb空间的总体分配

  19. SELECT t1.session_id,

  20. t1.internal_objects_alloc_page_count, t1.user_objects_alloc_page_count,

  21. t1.internal_objects_dealloc_page_count , t1.user_objects_dealloc_page_count,

  22. t3.*

  23. from sys.dm_db_session_space_usage t1 ,

  24. -- 反映每个session累计空间申请

  25. sys.dm_exec_sessions as t3

  26. -- 每个session的信息

  27. where

  28. t1.session_id = t3.session_id

  29. and (t1.internal_objects_alloc_page_count>0

  30. or t1.user_objects_alloc_page_count >0

  31. or t1.internal_objects_dealloc_page_count>0

  32. or t1.user_objects_dealloc_page_count>0)

  33. -- Query 3

  34. -- 返回正在运行并且做过空间申请的session正在运行的语句

  35. SELECT t1.session_id,

  36. st.text

  37. from sys.dm_db_session_space_usage as t1,

  38. sys.dm_exec_requests as t4

  39. CROSS APPLY sys.dm_exec_sql_text(t4.sql_handle) AS st

  40.  where t1.session_id = t4.session_id

  41.    and t1.session_id >50

  42. and (t1.internal_objects_alloc_page_count>0

  43. or t1.user_objects_alloc_page_count >0

  44. or t1.internal_objects_dealloc_page_count>0

  45. or t1.user_objects_dealloc_page_count>0)

  46. waitfor delay '0:0:1'

  47. end


推荐阅读:
  1. MongoDB查看当前操作db.currentOp()
  2. db2参数查看

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

db temp 查看

上一篇:夯实Java基础系列2:Java自动拆装箱里隐藏的秘密

下一篇:SQL SERVER中SQL优化

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》