Monitoring Tempdb in SQL Server 2005
from:
[@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:
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:
- Total Data File Size (in KB)
- Total Log File Size (in KB)
- Used data file size (in KB)
- Used Log File size (in KB)
- Free space left in tempdb (in KB)
- Space utilized by user objects (in KB)
- Space utilized by Internal objects (in KB)
- Space utilized by Version Store (in KB)
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:
- Sys.dm_db_file_space_usage
- Sys.dm_db_session_file_usage
- Sys.dm_db_task_space_usage
- sys.dm_exec_requests
- sys.dm_tran_active_snapshot_database_transactions
- sys.dm_exec_query_stats
- sys.dm_tran_version_store
- sys.dm_io_virtual_file_stats
By using the above DMVs, the tempdb usage can be easily tracked.
- Total Data File Size (in KB)
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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/66009/viewspace-1059126/,如需轉載,請註明出處,否則將追究法律責任。
|
相關文章
- SQL Server中tempdb的管理SQLServer
- Moving the tempdb database(SQL server)DatabaseSQLServer
- SQL Server 2000 shrink tempdbSQLServer
- SQL Server 2005中的tempdb資料庫的一些特點SQLServer資料庫
- 如何在SQL Server中最佳化TempdbSQLServer
- 關於SQL Server tempdb 的各種操作SQLServer
- SQL server 2005 expressSQLServerExpress
- 深刻的教訓——SQL Server關於TempDB的使用SQLServer
- SQL Server 2008效能故障排查(四)——TempDBSQLServer
- sql server 檢視tempdb使用的相關檢視SQLServer
- SQL Server中的TempDB管理——TempDB基本知識(為什麼需要版本儲存區)SQLServer
- Sql Server 2005函式SQLServer函式
- SQL SERVER 2005 配置-saSQLServer
- SQL SERVER2005建Link ServerSQLServer
- 認識SQL Server2000 tempdb資料庫SQLServer資料庫
- SQL Server中TempDB管理(version store的邏輯結構)SQLServer
- 在SQL Server tempdb滿時檢查資料檔案SQLServer
- Sql Server 2005新增T-sql特性SQLServer
- XML Support in Microsoft SQL Server 2005XMLROSSQLServer
- PowerShell連線 SQL Server 2005SQLServer
- 微軟SQL Server 2005速成版微軟SQLServer
- SQL Server2005快捷鍵SQLServer
- SQL SERVER 2005映象實驗SQLServer
- SQL Server 2005 Service Broker 初探SQLServer
- SQL Server 2005 Express Edition 概述SQLServerExpress
- SQL Server 2005:清空plan cacheSQLServer
- SQL Server 2005中修改 Server Collation的方法SQLServer
- SQL Server中TempDB管理(版本儲存區的一個example)SQLServer
- sql server 2005資料庫快照SQLServer資料庫
- 配置SQL Server 2005伺服器SQLServer伺服器
- SQL SERVER 2005表分割槽功能SQLServer
- SQL Server 2005動態管理物件SQLServer物件
- 實戰 SQL Server 2005 映象配置SQLServer
- Sql server 2005中output用法解析SQLServer
- Sql Server 2005 日誌壓縮SQLServer
- SQL SERVER 2005 日誌收縮SQLServer
- sql server 2005使用點滴(1)SQLServer
- SQL Server 2005 Cluster 叢集部署SQLServer