溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

查看temp db

發(fā)布時間:2020-08-08 10:00:27 來源:ITPUB博客 閱讀:162 作者:o0yuki0o 欄目:關(guān)系型數(shù)據(jù)庫
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


-- 這個管理視圖能夠反映當(dāng)時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. -- 這個管理視圖能夠反映當(dāng)時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


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI