T-SQL: DBCC CHECKALLOC

DBCC CHECKALLOC (Transact-SQL) 

檢查指定數據庫的磁盤空間分配結構的一致性。

語法

DBCC CHECKALLOC
[
        ( 'database_name' | database_id | 0
      [ , NOINDEX
      | , { REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST | REPAIR_REBUILD } ]
        )
    [ WITH
        {
          [ ALL_ERRORMSGS ]
          [ , NO_INFOMSGS ]
          [ , TABLOCK ]
          [ , ESTIMATEONLY ]
        }
    ]
]
參數

'database_name' | database_id | 0

要檢查其分配和頁使用情況的數據庫的名稱或 ID。如果未指定,或者指定爲 0,則使用當前數據庫。

數據庫名稱必須符合

NOINDEX

指定不檢查用戶表的非聚集索引。

REPAIR_ALLOW_DATA_LOSS | REPAIR_FAST | REPAIR_REBUILD

指定 DBCC CHECKALLOC 修復找到的錯誤。database_name 必須處於單用戶模式。

REPAIR_ALLOW_DATA_LOSS

試圖修復找到的任何錯誤。這些修復可能會導致一些數據丟失。REPAIR_ALLOW_DATA_LOSS 是允許修復分配錯誤的唯一選項。

REPAIR_FAST

保留語法只是爲了向後兼容。未執行修復操作。

REPAIR_REBUILD

不適用。

WITH

啓用要指定的選項。

ALL_ERRORMSGS

顯示所有錯誤消息。如果未指定,則 SQL Server 2005 數據庫引擎 將按每個對象最多 200 條錯誤消息進行顯示。

NO_INFOMSGS

取消所有信息性消息和關於所用空間的報告。

TABLOCK

使 DBCC 命令獲取排他數據庫鎖。

ESTIMATE ONLY

顯示當指定所有其他選項時運行 DBCC CHECKALLOC 所需的估計 tempdb 空間大小。

標識符規則。
備註

DBCC CHECKALLOC 將檢查數據庫中所有頁的分配,而不管其所屬的頁類型或對象類型。它還可驗證各種內部結構,這些結構可用於跟蹤這些頁以及它們之間的關係。

如果未指定 NO_INFOMSGS,則 DBCC CHECKALLOC 將收集有關數據庫中所有對象的空間使用情況信息。然後將這一信息與找到的任何錯誤一起進行打印。

內部數據庫快照

瞭解 DBCC 錯誤消息

錯誤報告

糾正錯誤

鎖模式
結果集

下表說明了 DBCC CHECKALLOC 返回的信息。

說明

FirstIAM

僅供內部使用。

Root

僅供內部使用。

Dpages

數據頁計數。

Pages used

分配的頁。

Dedicated extents

分配給對象的區數。

如果使用混合分配頁,則可能有未分配區數的頁。

DBCC CHECKALLOC 還會報告每條索引和每個文件中分區的分配摘要。此摘要說明了數據的分佈情況。

說明

Reserved pages

分配給索引的頁和已分配區數中未使用的頁。

Used pages

分配給索引和索引正在使用的頁。

Partition ID

僅供內部使用。

Alloc unit ID

僅供內部使用。

In-row data

頁包含索引或堆數據。

LOB data

頁包含 varchar(max)、nvarchar(max)、varbinary(max)、text、ntext、xml 和 image 數據。

Row-overflow data

頁包含已推送到行外的可變長度列數據。

DBCC CHECKALLOC 將返回以下結果集(值可能有所不同),指定了 ESTIMATEONLY 或 NO_INFOMSGS 時除外。

如果指定了 ESTIMATEONLY,則 DBCC CHECKALLOC 將返回以下結果集。

Estimated TEMPDB space needed for CHECKALLOC (KB)
-------------------------------------------------
34

(1 row(s) affected)

DBCC execution completed. If DBCC printed error messages, contact your system administrator.
權限
DBCC results for 'master'.
***************************************************************
Table sysobjects                Object ID 1.
Index ID 1         FirstIAM (1:11)   Root (1:12)    Dpages 22.
    Index ID 1. 24 pages used in 5 dedicated extents.
Index ID 2         FirstIAM (1:1368)   Root (1:1362)    Dpages 10.
    Index ID 2. 12 pages used in 2 dedicated extents.
Index ID 3         FirstIAM (1:1392)   Root (1:1408)    Dpages 4.
    Index ID 3. 6 pages used in 0 dedicated extents.
Total number of extents is 7.
***************************************************************
'...'
***************************************************************
Table spt_server_info                Object ID 1938105945.
Index ID 1         FirstIAM (1:520)   Root (1:508)    Dpages 1.
    Index ID 1. 3 pages used in 0 dedicated extents.
Total number of extents is 0.
***************************************************************
Processed 52 entries in sysindexes for database ID 1.
File 1. Number of extents = 210, used pages = 1126, reserved pages = 1280.
           File 1 (number of mixed extents = 73, mixed pages = 184).
    Object ID 1, Index ID 0, data extents 5, pages 24, mixed extent pages 9.
'...'
    Object ID 1938105945, Index ID 0, data extents 0, pages 3, mixed extent pages 3.
Total number of extents = 210, used pages = 1126, reserved pages = 1280 in this database.
       (number of mixed extents = 73, mixed pages = 184) in this database.
CHECKALLOC found 0 allocation errors and 0 consistency errors in database 'master'.
DBCC results for 'master'.
***************************************************************
Table sys.sysrowsetcolumns                Object ID 4.
Index ID 1, partition ID 262144, alloc unit ID 262144 (type In-row data). FirstIAM (1:98). Root (1:94). Dpages 7.
Index ID 1, partition ID 262144, alloc unit ID 262144 (type In-row data). 9 pages used in 1 dedicated extents.
Index ID 1, partition ID 262144, alloc unit ID 262398 (type Row-overflow data). FirstIAM (0:0). Root (0:0). Dpages 0.
Index ID 1, partition ID 262144, alloc unit ID 262398 (type Row-overflow data). 0 pages used in 0 dedicated extents.
Total number of extents is 1.
...
***************************************************************
Processed 201 entries in system catalog for database ID 1.
File 1. Number of extents = 44, used pages = 300, reserved pages = 345.
           File 1 (number of mixed extents = 29, mixed pages = 225).
    Object ID 4, index ID 1, partition ID 262144, alloc unit ID 262144 (type In-row data), data extents 1, pages 9, mixed extent pages 8.
    Object ID 5, index ID 1, partition ID 327680, alloc unit ID 327680 (type In-row data), data extents 0, pages 2, mixed extent pages 2.
    Object ID 7, index ID 1, partition ID 458752, alloc unit ID 458752 (type In-row data), data extents 0, pages 5, mixed extent pages 5.
    Object ID 8, index ID 0, partition ID 524288, alloc unit ID 524288 (type In-row data), data extents 0, pages 2, mixed extent pages 2.
    Object ID 13, index ID 1, partition ID 851968, alloc unit ID 851968 (type In-row data), data extents 1, pages 9, mixed extent pages 8.
    Object ID 15, index ID 1, partition ID 983040, alloc unit ID 983040 (type In-row data), data extents 0, pages 2, mixed extent pages 2.
    Object ID 26, index ID 1, partition ID 281474978414592, alloc unit ID 1703937 (type In-row data), data extents 0, pages 3, mixed extent pages 3.
    Object ID 27, index ID 1, partition ID 281474978480128, alloc unit ID 1769473 (type In-row data), data extents 0, pages 3, mixed extent pages 3.
    Object ID 27, index ID 2, partition ID 562949955190784, alloc unit ID 1769474 (type In-row data), index extents 0, pages 3, mixed extent pages 3.
...
    Object ID 1179151246, index ID 1, partition ID 72057594038845440, alloc unit ID 13435136 (type In-row data), data extents 2, pages 18, mixed extent pages 8.
    Object ID 1179151246, index ID 2, partition ID 72057594038910976, alloc unit ID 13566208 (type In-row data), index extents 1, pages 16, mixed extent pages 8.
    Object ID 1911677858, index ID 0, partition ID 72057594039631872, alloc unit ID 15073536 (type In-row data), data extents 0, pages 2, mixed extent pages 2.
Total number of extents = 41, used pages = 289, reserved pages = 323 in this database.
       (number of mixed extents = 27, mixed pages = 211) in this database.
CHECKALLOC found 0 allocation errors and 0 consistency errors in database 'master'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
示例
-- Check the current database.
DBCC CHECKALLOC;
GO
-- Check the AdventureWorks database.
DBCC CHECKALLOC ('AdventureWorks');
GO
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章