搜尋本站文章

2008-05-12

檢視資料庫,其硬碟使用空間與資料實際使用空間;Displays the disk space reserved and used by the whole database


檢視資料庫,其硬碟使用空間與資料實際使用空間

先前使用 undocumented command:DBCC showfilestats 與 'DBCC SQLPERF(LOGSPACE) 等方式,取得資料庫的硬碟使用空間與資料實際使用空間之資訊。
筆者這邊再提供一個方式,利用目錄檢視:sys.database_files,也可以取得相關的磁碟空間的使用資訊。

這範例是包含:資料檔案與交易記錄檔案的空間使用資訊。

USE [目標資料庫]
GO
SELECT name N'邏輯名稱' , size/128.0 N'使用的磁碟空間(MB)' ,
CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 N'資料實際上使用的空間(MB)'
,size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 N'剩餘的可用空間(MB)'
FROM sys.database_files;


請參考下圖所示:


參考資料:
檢視全部的資料庫,其交易記錄檔案所使用的空間資訊; Transaction log space usage statistics for all databases
http://sharedderrick.blogspot.com/2008/01/transaction-log-space-usage-statistics.html

顯示資料庫所使用的磁碟空間、資料實際所使用的空間; Displays the disk space reserved and used by the whole database
http://sharedderrick.blogspot.com/2008/01/displays-disk-space-reserved-and-used.html

顯示每一個資料庫的所使用的磁碟空間之完整版本; Displays the disk space reserved and used by the each database
http://sharedderrick.blogspot.com/2008/01/displays-disk-space-reserved-and-used_02.html

沒有留言:

張貼留言