TempDB用来存放临时表、全局临时表、表变量以及排序或HASH等操作引发的中间结果集

TempDB在每次实例重启时重新创建,TempDB数据库文件的初始化大小取决于Model数据库的文件大小或显示ALTER语句设置的TempDB的文件文件大小

在每个数据库文件中,分配页(allocation page)ID:

PFS:1

GAM:2

SGAM:3

一个PFS页能覆盖8088个数据页,一个GAM或SGAM页能覆盖511232个数据页,当一个文件超过响应数据页数,SQL SERVER 使用分配页(allocation page)链来覆盖。

---------------------------------------------------------------------------------

由于临时表和表变量创建和销毁时,需要锁住分配页来为临时表或表变量分配数据页,当创建和销毁的过于频繁时,会造成ALLOCATION BOTTLENECK

查看是否是Allocation BottleNeck:

SELECT *

FROM sys.dm_os_waiting_tasks

WHERE wait_type LIKE 'PAGE%LATCH_%'

AND resource_description LIKE '2:%'

解决ALLOCATION BOTTLENECK的方法:

1. 建立与CORE或CPU相同个数的物理文件数

2. 使用TF1118(SQL SERVER 2005后),为新对象分配数据页时分配到新数据区而不使用混合区,减少SGAM的争用

---------------------------------------------------------------------------------

由于临时表和表变量创建和销毁时,需要对相关系统表插入或删除该临时表的元数据信息,当创建和销毁的过于频繁时,便会造成DDL BottleNeck

查看DDL BottleNeck:

SELECT *

FROM sys.dm_os_waiting_tasks

WHERE wait_type LIKE 'PAGE%LATCH_%'

AND resource_description LIKE '2:%'

查看DDL BottleNeck和查看Allocation BottleNeck的脚本一样,但是两者锁定的资源不一样

或使用性能计数器来判断:

SELECT * FROM sys.dm_os_performance_counters

WHERE counter_name LIKE '%temp%table%'

'Active Temp Tables':当前使用中的临时表

'Temp Tables Creation Rate':每秒创建的临时表或表变量的个数

'Temp Tables For Destruction':等待系统进程清理的表变量或临时表的个数

当'Temp Tables Creation Rate'和'Temp Tables For Destruction'值较高时,则可能存在DDL BottleNeck

解决方案:

1. 将频繁创建和删除的临时表或表变量改为用户表

---------------------------------------------------------------------------------

在TempDB上,由于某些不合理的执行计划和SQL消耗大量的空间,造成Space BottleNeck

查看Space BottleNeck:

-- This DMV query shows currently executing tasks and

-- tempdb space usage

-- Once you have isolated the task(s) that are generating lots

-- of internal object allocations,

-- you can even find out which TSQL statement and its query plan

-- for detailed analysis

SELECT TOP 10

t1.session_id,

t1.request_id,

t1.task_alloc,

t1.task_dealloc,

(

SELECT SUBSTRING(TEXT, t2.statement_start_offset/2 + 1,

(CASE WHEN statement_end_offset = -1

THEN LEN(CONVERT(NVARCHAR(MAX),TEXT)) * 2

ELSE statement_end_offset

END - t2.statement_start_offset)/2)

FROM sys.dm_exec_sql_text(sql_handle)

) AS query_text,

(SELECT query_plan FROM sys.dm_exec_query_plan(t2.plan_handle)) AS query_plan

FROM

(SELECT session_id, request_id,

SUM(internal_objects_alloc_page_count +   user_objects_alloc_page_count) AS task_alloc,

SUM (internal_objects_dealloc_page_count + user_objects_dealloc_page_count) AS task_dealloc

FROM sys.dm_db_task_space_usage

GROUP BY session_id, request_id

) AS t1,

sys.dm_exec_requests AS t2

WHERE t1.session_id = t2.session_id AND

(t1.request_id = t2.request_id) AND

t1.session_id > 50

ORDER BY t1.task_alloc DESC

解决方案:

1. 找出耗空间较大的SQL并优化

---------------------------------------------------------------------------------

参考:

http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/01/12/tempdb-monitoring-and-troubleshooting-out-of-space.aspx

Tempdb--monitoring and troubleshooting的更多相关文章

  1. SQL Server 2008性能故障排查(四)——TempDB

    原文:SQL Server 2008性能故障排查(四)--TempDB 接着上一章:I/O TempDB: TempDB是一个全局数据库,存储内部和用户对象还有零食表.对象.在SQLServer操作过 ...

  2. 【译】The Accidental DBA:Troubleshooting Performance

    最近重新翻看The Accidental DBA,将Troubleshooting Performance部分稍作整理,方便以后查阅.此篇是Part 2Part 1:The Accidental DB ...

  3. Announcing the Operate Preview Release: Monitoring and Managing Cross-Microservice Workflows

    转自:https://zeebe.io/blog/2019/04/announcing-operate-visibility-and-problem-solving/   Written by Mik ...

  4. SQL Server 2008性能故障排查(一)——概论

    原文:SQL Server 2008性能故障排查(一)--概论 备注:本人花了大量下班时间翻译,绝无抄袭,允许转载,但请注明出处.由于篇幅长,无法一篇博文全部说完,同时也没那么快全部翻译完,所以按章节 ...

  5. Managing a node remotely by using the netapp SP

    Managing a node remotely by using the Service Processor The Service Processor (SP) is a remote manag ...

  6. Monitor and diagnose performance in Java SE 6--转载

    Java SE 6 provides an in-depth focus on performance, offering expanded tools for managing and monito ...

  7. Java Performance Optimization Tools and Techniques for Turbocharged Apps--reference

    Java Performance Optimization by: Pierre-Hugues Charbonneau reference:http://refcardz.dzone.com/refc ...

  8. (转)db2top详解

    原文:https://blog.csdn.net/lyjiau/article/details/47804001 https://www.ibm.com/support/knowledgecenter ...

  9. ZooKeeper Administrator's Guide A Guide to Deployment and Administration(吃别人嚼过的馍没意思,直接看官网资料)

    Deployment System Requirements Supported Platforms Required Software Clustered (Multi-Server) Setup ...

  10. CNCF CloudNative Landscape

    cncf landscape CNCF Cloud Native Interactive Landscape 1. App Definition and Development 1. Database ...

随机推荐

  1. [转]Aspose.Words.dll 将 Word 转换成 html

    用于网站上,上传 Word 文档后显示文档内容(可看作在线阅读).代码适用于 .net 2.0 或以上版本 (使用的未注册 Aspose.Words.dll 并尝试消除试用标志) 下载地址 strin ...

  2. ssh登录很慢的问题

    1.关闭ssh DNS反向解析 vi /etc/ssh/sshd_config 修改UseDNS no 2.关闭 GSSAPI 的用户认证   vi /etc/ssh/sshd_config 修改GS ...

  3. Traits

    'folly/Traits.h' Implements traits complementary to those provided in <type_traits> Implements ...

  4. Bootstrap的介绍和响应式媒体查询

    Bootstrap的介绍 凡是使用过Bootstrap的开发者,都不在乎做这么两件事情:复制and粘贴.哈哈~,是的使用Bootstrap非常简单,但是在复制粘贴之前,需要先对Bootstrap的用法 ...

  5. Python普通方法、静态方法、类方法

    开始 # -*-coding:utf-8-*- # 普通方法,类方法,静态方法的区别 __metaclass__ = type class Tst: name = 'tst' data = 'this ...

  6. ggplot2 texts : Add text annotations to a graph in R software

    http://www.sthda.com/english/wiki/ggplot2-texts-add-text-annotations-to-a-graph-in-r-software Instal ...

  7. WordVBA常用项

    将光标所在段落选中 Selection.MoveUp unit:=wdParagraphSelection.MoveDown unit:=wdParagraph, Extend:=wdExtend ' ...

  8. Xshell连接虚拟机突然被拒,提示再次输入密码。。。

    sudo vim /etc/ssh/sshd_config 将 # Authentication: LoginGraceTime 120 PermitRootLogin prohibit-passwo ...

  9. libcurl 调用curl_easy_getinfo( ) 返回错误码对照

    //执行设置好的操作 res = curl_easy_perform(easy_handle); //获取HTTP错误码 ; curl_easy_getinfo(easy_handle, CURLIN ...

  10. eclipse双击变量高亮显示开关

    在eclipse/myeclipse中如果不小心把变量的高亮显示弄丢了.可真是件愁人的事,不过看到这你就不用愁了 windows->   preferences-> java-> E ...