DMV to track the temp file usage for SQLServer

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

时间: 2024-11-11 18:53:50

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

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 这是由于该磁盘的空间已经满了,这时候可以进行扩容,或者将该磁盘的部分目录迁移到别的磁盘. 以下为解决思路,查找最大的文件,然后将其干掉: 1.使用命令df -h 查看硬盘空间 2.命令top查看cpu及内存 3.使用命令du -h –max-depth=1 /var/log/* 查看/var/log路

cannot create temp file for here-document: No space left on device

今天登陆系统在cd 到某个目录使用tab键的时候报错了 linux很友好的提示了:不能创建临时文件文档:设备上没有剩余空间(告诉我们磁盘满了) du -sh /* 查看哪个目录最大,一步一步的查找大文件 我这里是跑了好多个tomcat实例,所以没做日志的处理,所以导致磁盘占满 写一个定时删除前7天的日志删除脚本就行了

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

使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linux 下使用 shell 脚本来监控 Oracle 告警日志(monitor alter log file). Linux Shell的相关参考:        Linux/Unix shell 脚本中调用SQL,RMAN脚本        Linux/Unix shell sql 之间传递变量   

Redis源码解析(十五)--- aof-append only file解析

继续学习redis源码下的Data数据相关文件的代码分析,今天我看的是一个叫aof的文件,这个字母是append ONLY file的简称,意味只进行追加文件操作.这里的文件追加记录时为了记录数据操作的改变记录,用以异常情况的数据恢复的.类似于之前我说的redo,undo日志的作用.我们都知道,redis作为一个内存数据库,数据的每次操作改变是先放在内存中,等到内存数据满了,在刷新到磁盘文件中,达到持久化的目的.所以aof的操作模式,也是采用了这样的方式.这里引入了一个block块的概念,其实就

Azure 上为Liunx VM 挂载File类型的存储。

1. Create a storage account in Azure, copy the storage account endpoint URL (with postfix of "file.core.chinacloudapi.cn") and storage access key to a temp file. 2. Download and install Azure CLI: https://www.azure.cn/documentation/articles/xpla

[2] Manage File,Dir,User,Group

Root directory introduce: dev : Device directoryetc : System software startup and confighome: User main directorylib :C complier directory/libarymnt : host plug/unplug deviceproc: System directory, process infomationroot: Super user main directorytmp

File中操作路径的API(转)

这几天一直在搞Java,模板引擎系列和程序猿执业修养系列都暂停了,在Java上忙的不亦乐乎!由于对Java还不太熟悉,经历了各种纠结终于完成了任务.以下是关于Java获取当前目录的方法的备忘录. 原文地址:http://www.cnblogs.com/diyunpeng/archive/2011/06/06/2073567.html 1.利用System.getProperty()函数获取当前路径:System.out.println(System.getProperty("user.dir&q

ArcSDE for Oracle表空间管理——暂时(TEMP)表空间

Oracle暂时表空间主要用来做查询和存放一些缓冲区数据.暂时表空间消耗的主要原因是须要对查询的中间结果进行排序. 重新启动数据库能够释放暂时表空间,假设不能重新启动实例,而一直保持问题sql语句的运行,temp表空间会一直增长.直到耗尽硬盘空间. 下面操作会占用大量的temporary:    1.用户运行imp/exp 导入导出操作时,会使用大量的temporary段    2.用户在Create 或者 rebuild index时    3.运行create table ...... as

Crystal Reports "Access to report file denied. Another program may be using it."

I encounter this problem several times, the way to get around this is to give "Everyone or Network Service " permission to "C:\windows\temp" folder. I gave everyone on my development box just for convenient. I hope it will help you sol