from: http://www.sqllion.com/2009/05/monitoring-tempdb-in-sql-server-2005/
[@more@]As the tempdb database is the common global resource for all the operations going on in SQL Server, so the DBA has to be bit cautious about the use of it. Because any unexpected operations by the applications running under the SQL Server instance or any uneven query by the user can eat all the space available to thetempdb resulting decrease in the performance of all other applications running under the same instance.
So it is necessary to keep track the usage of tempdb database by various applications and processes and to take necessary actions when the size falls down below the threshold limit. Monitoring tempdb over time will help in determining the optimal size of the tempdb.
Check my earlier post for more details on performance regarding tempdb:
http://www.sqllion.com/2009/05/optimizing-tempdb-in-sql-server-2005/
Use the below query to check the current tempdb size:
SELECT
[name] AS [Logical File Name],
CASE type_desc
WHEN 'ROWS' THEN 'Data'
WHEN 'LOG' THEN 'Log'
END AS [File Type],
physical_name AS [File Path],
[size] AS [File Size],
CASE growth
WHEN 0 THEN 'Enabled'
ELSE 'Disabled'
END AS [Auto Growth]
FROM tempdb.sys.database_files
Output:
Logical File Name | File Type | File Path | File Size (in KB) | Auto Growth |
tempdev | Data | D:Program FilesMicrosoft SQL ServerMSSQL.2MSSQLDATAtempdb.mdf | 8192 | Enabled |
templog | Log | D:Program FilesMicrosoft SQL ServerMSSQL.2MSSQLDATAtemplog.ldf | 512 | Enabled |
To get a brief info on the space used by tempdb database, use the below query:
USE tempdb
GO
EXEC sp_spaceused
Output:
database_name | database_size | unallocated space |
tempdb | 8.50 MB | 6.82 MB |
reserved | data | index_size | unused |
1208 KB | 528 KB | 608 KB | 72 KB |
Luckily SQL Server provides a rich set of DMVs (dynamic management views) to keep track of some performance counters that will help in managing disk usage by tempdb database.
So in order to properly manage tempdb, the below performance factors can be tracked:
There is one more major factor influencing the performance of tempdb i.e. I/O. If you have a slow I/O subsystem, then your I/O requests are queued up resulting in I/O bottleneck. When a user connects to a database, a session is created. And the DMV tracks all the events like allocation or deallocation of pages in tempdb for each active session. The session will remain active till the user disconnects.
[Note: Details about I/O performance will be posted soon.]
To achieve the above performance factors, the below DMVs can be used:
By using the above DMVs, the tempdb usage can be easily tracked.
Space used by different components in tempdb database.sys.sysfiles: Returns information for each file in the database.sys.dm_io_virtual_file_stats: Returns I/O statistics for data and log files. It takes two parameters out of which one is Database ID (show all databases if NULL is provided) and File ID (show all files if NULL is provided).
SELECT
DDB_NAME(database_id) as [Database Name],
[Name] as [Logical Name],
[filename] as [File Name],
[size_on_disk_bytes] / 1024 as [Size (in KB)]
FROM
sys.dm_io_virtual_file_stats(2, 1)
-- 2(tempdb database id), 1(tempdb data file id)
inner join
sys.sysfiles
on sys.dm_io_virtual_file_stats.file_id = sys.sysfiles.fileid
Output:
Database Name | Logical Name | File Name
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英 2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce SQLServer2000教程简单入门 Sql Server 2005 日志压缩 SharePoint 2010图文安装教程 Excel中如何设置批注格式 安装SQL2000简体中文(企业版)的流程 sql2000安装教程 电脑怎么安装TTF字体文件(附TTF文件打不开解决方法) mac下载App Store应用提示“损坏”怎么办 电脑定时关机怎么设置 分区助手怎么将一个区分成几个 如何将一个分区再分成几个分区 |
