There are three DMVs you can use to track tempdb usage:

sys.dm_db_task_space_usage
sys.dm_db_session_space_usage
sys.dm_db_file_space_usage

The first two will allow you to track allocations at a query & session level. The third tracks allocations across version store, user and internal objects.

The following example query will give you allocations per session:

SELECT
s.session_id AS [SESSION ID]
,DB_NAME(database_id) AS [DATABASE Name]
,HOST_NAME AS [System Name]
,program_name AS [Program Name]
,login_name AS [USER Name]
,status
,cpu_time AS [CPU TIME (in milisec)]
,total_scheduled_time AS [Total Scheduled TIME (in milisec)]
,total_elapsed_time AS [Elapsed TIME (in milisec)]
,(memory_usage * 8) AS [Memory USAGE (in KB)]
,(user_objects_alloc_page_count * 8) AS [SPACE Allocated FOR USER Objects (in KB)]
,(user_objects_dealloc_page_count * 8) AS [SPACE Deallocated FOR USER Objects (in KB)]
,(internal_objects_alloc_page_count * 8) AS [SPACE Allocated FOR Internal Objects (in KB)]
,(internal_objects_dealloc_page_count * 8) AS [SPACE Deallocated FOR Internal Objects (in KB)]
,CASE is_user_process
WHEN 1 THEN 'user session'
WHEN 0 THEN 'system session'
END AS [SESSION Type],
s.row_count AS [ROW COUNT]
FROM sys.dm_db_session_space_usage su INNER join sys.dm_exec_sessions s ON su.session_id = s.session_id

Below are the situation when SQL Server will use the temp file.

  1. usage of table variables or temporary tables
  2. sql server created intermediate resultsets as worktables in tempdb - usually for sorting purposes (usually is a sign of absent indexes/out-of-date statistics)
  3. sql server decided to pre-evaluate the resultset of table valued function and in this case it stores the data in tempdb
  4. recreating indexes with option SORT_IN_TEMPDB = ON

DMV to track the temp file usage for SQLServer的更多相关文章

  1. cd tom-bash: cannot create temp file for here-document: No space left on device

    Linux使用tab补全时提示 cd tom-bash: cannot create temp file for here-document: No space left on device 这是因为 ...

  2. Linux命令行报错 bash: cannot create temp file for here-document: No space left on device

    今天Linux服务器出问题了,使用"tab"补全命令时,提示 bash: cannot create temp file for here-document: No space l ...

  3. Linux出现cannot create temp file for here-document: No space left on device的问题解决

    在终端输入:cd /ho 按tab键时,显示错误: bash: cannot create temp file for here-document: No space left on device 这 ...

  4. 【linux基础err】bash: cannot create temp file for here-document: No space left on device

    博主的device还有剩余空间也出现了这个问题,不知是什么原因,不过删除一些无用的内容,或者将某些有用的内容移动到其他硬盘,之后就可以正常使用了. 参考: 1. cannot create temp ...

  5. 服务器爆满:cannot create temp file for here-document: No space left on device

    1 概述 服务器的磁盘空间被占满导致TAB补全指令失效(TAB会创建临时文件) cannot create temp file for here-document: No space left on ...

  6. bash: cannot create temp file for here-document: Read-only file system

    文件系统被强制只读问题,第一眼看到百度了一下,说可能磁盘坏了.卧槽我都吓懵了系统盘坏了,闹着玩呢,然后接着查资料,排查 mount 查看所有挂载,发现根目录的挂载权限是ro只读. /dev/sda2 ...

  7. ls bash: cannot create temp file for here-document: No space left on device

    出现这种问题,一般是磁盘空间满了,或者是inode满了 使用命令: df -h查询磁盘空间 df -i 查询inode占用 Filesystem Inodes IUsed IFree IUse% Mo ...

  8. 【应用服务 App Service】App Service使用Git部署时,遇见500错误

    问题描述 Azure App Service在部署的时候支持多种方式,如Zip,VS 2019, VS Code,或者是Git部署,当使用Git部署遇见500错误时,可以通过其他的部署方式来验证是否也 ...

  9. Linux/Unix shell 监控Oracle告警日志(monitor alter log file)

    使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linu ...

随机推荐

  1. SQL中distinct的用法(转自博主:Rain Man)

    在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出不同(distinct)的值.关键词 distinct用于返回唯一不同的值. 表A: 示例1 select distinct nam ...

  2. RN组件之ViewPagerAndroid

    一.ViewPagerAndroid 1.一个允许在子视图之间左右翻页的容器.每一个ViewPagerAndroid的子容器会被视作一个单独的页,并且会被拉伸填满 ViewPagerAndroid.注 ...

  3. lucene 3.0.2 操作进阶

    转自:Bannings http://blog.csdn.net/zhangao0086/article/details/ Analyzer(分词器) 分词器能以某种规则对关键字进行分词,将分好的词放 ...

  4. 2016.03.31,英语,《Vocabulary Builder》Unit 08

    tend/tent: from the Latin tendere, meaning 'to stretch, extend, or spread'. tent: [tent] n. 帐篷 vt.&a ...

  5. [IT思考]技术领先对手多少算好?

    坦白讲,很多做技术的公司,总是觉得技术越“牛”越好.但是,历史也曾经出现过,很多公司技术的确很棒,但是市场反响一般(待补充案例).结果可想而知. 要知道,每一个新技术,尤其是业界领先的新技术,需要不少 ...

  6. commandname+commandargument

    (一) CommandName:其实可以设置成一种动作,比如Select,Update,Delete,等操作.就是说CommandName是确定他到底引发的是哪一事件,如果CommandName的名字 ...

  7. select * 所有字段时如何巧妙的使用覆盖索引

    内容从"mysql高性能书籍"  179页摘取 当select * 时.往往使用不到索引..效率不高,因为查询从表中选择所有的列,没有任何索引能覆盖所有的列.不过还是有捷径可以利用 ...

  8. 免费手机号码归属地API查询接口和PHP使用实例分享

    免费手机号码归属地API查询接口和PHP使用实例分享 最近在做全国性的行业分类信息网站,需要用到手机号归属地显示功能,于是就穿梭于各大权威站点之间偷来了API的接口地址. 分享出来,大家可以用到就拿去 ...

  9. 20145235《Java程序设计》第7周学习总结

    教材学习内容总结 13.1 认识时间与日期 格林威治时间(GMT):通过观察太阳而得,因为地球公转轨道为椭圆形且速度不一,本身自传减速而造成误差. 世界时(UT):通过观测远方星体跨过子午线而得,受地 ...

  10. javaWeb中struts开发——Bean标签

    1.struts标签库中常用标签 使用myeclise标签可以自动注入,其中,前三个是经常使用的,主要的是logic标签 2.Bean标签 Bean标签主要用来定义和访问JavaBean,在Strut ...