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. elasticsearch2.2 集群搭建各种坑

        目前生产环境的es版本是1.0版本,需要升级到最新的2.2版本,于是在测试环境进行部署集群测试,在测试过程中遇到的坑相当多,下面详细介绍下.       1. 版本升级到2.2后,必须建一个单 ...

  2. C#的async和await

    C# 5.0中引入了async 和 await.这两个关键字可以让你更方便的写出异步代码. 看个例子: public class MyClass { public MyClass() { Displa ...

  3. 二分查找算法java实现

    今天看了一下JDK里面的二分法是实现,觉得有点小问题.二分法的实现有多种今天就给大家分享两种.一种是递归方式的,一种是非递归方式的.先来看看一些基础的东西. 1.算法概念. 二分查找算法也称为折半搜索 ...

  4. php phpeclipse + xampp 配置安装过程

    就想test是否能配置成功,下载apache,php5.3,安装开始 apache的安装,一路next,遇到Server Information,随便填写即可,安装路径自己可选 php的安装,将下载的 ...

  5. FZU 1018 枚举dp

    题意 给出一个数字组成的立方体 在其中选取一个体 使这个体中的数字之和最小 不可以不选 fzu的题目分类动态规划里面不是按难度排得 是按照题号..记得以前做题碰到过算 矩阵里面求子矩阵的最大和的 不会 ...

  6. 解决mysql出现“the table is full”的问题

    解决mysql出现“the table is full”的问题 2010-12-20 09:15:17 分类: LINUX 今天中午收到mysql错误日志监控发来的警报,错误日志如下: 101209 ...

  7. HTML: Css引入的四種方式

    哪四種?這裏簡單進行下總結 ①寫在 style 標籤中 <style type="text/css"> 這裏是css代碼... </style> ②外部引入 ...

  8. Jquery scrollTop animate 實現動態滾動到頁面頂部

    這個方法之前都是用的錨點實現的,但是效果僵硬,動感不足! 之後參考了一些網站,發現都是用的js,於是自己想到用jquery 來做一個插件也來實現以下這個小功能. $.fn.backTop = func ...

  9. PHP文件操作 之往一个文件写入数据

    //打开一个文件 $f = fopen($filename,'wb'); $filename:打开一个文件,不存在则自动创建,如果不能创建,说明指定的文件目录有错误 wb:写入的方式 ---- 覆盖原 ...

  10. Java的访问控制

       类内部  本包(实例.类变量和方法)  子类(任何位置) 外部包(实例.类变量和方法) public    √  √  √  √ protected   √  √  √  × default  ...