DBCC CHECKFILEGROUP (Transact-SQL)
Checks the allocation and structural integrity of all tables and indexed views in the specified filegroup of the current database.
DBCC CHECKFILEGROUP and DBCC CHECKDB are similar DBCC commands. The main difference is that DBCC CHECKFILEGROUP is limited to the single specified filegroup and required tables.
DBCC CHECKFILEGROUP performs the following commands:
Running DBCC CHECKALLOC or DBCC CHECKTABLE separately from DBCC CHECKFILEGROUP is not required.
Internal Database Snapshot
DBCC CHECKFILEGROUP uses an internal database snapshot to provide the transactional consistency that it must have to perform these checks. For more information, see Understanding Sparse File Sizes in Database Snapshots and the "DBCC Internal Database Snapshot Usage" section in DBCC (Transact-SQL).
If a snapshot cannot be created, or the TABLOCK option is specified, DBCC CHECKFILEGROUP acquires locks to obtain the required consistency. In this case, an exclusive database lock is required to perform the allocation checks, and shared table locks are required to perform the table checks. TABLOCK causes DBCC CHECKFILEGROUP to run faster on a database under heavy load, but decreases the concurrency available on the database while DBCC CHECKFILEGROUP is running.
Running DBCC CHECKFILEGROUP against tempdb does not perform any allocation checks and must acquire shared table locks to perform table checks. This is because, for performance reasons, database snapshots are not available on tempdb. This means that the required transactional consistency cannot be obtained.
Checking Objects in Parallel
By default, DBCC CHECKFILEGROUP performs parallel checking of objects. The degree of parallelism is automatically determined by the query processor. The maximum degree of parallelism is configured just like parallel queries. To restrict the maximum number of processors available for DBCC checking, use sp_configure. For more information, see max degree of parallelism Option.
Parallel checking can be disabled by using trace flag 2528. For more information, see Trace Flags (Transact-SQL).
Nonclustered Indexes on Separate Filegroups
If a nonclustered index in the specified filegroup is associated with a table in another filegroup, the index is not checked because the base table is not available for validation. This is a change in behavior in SQL Server 2005. In earlier versions of SQL Server, the nonclustered index and the base table in the other filegroup are checked. To check both the nonclustered indexes and the base tables, run DBCC CHECKDB.
If a table in the specified filegroup has a nonclustered index in another filegroup, the nonclustered index is not checked because of the following:
The base table structure is not dependent on the structure of a nonclustered index. Nonclustered indexes do not have to be scanned to validate the base table.
The DBCC CHECKFILEGROUP command validates objects only in the specified filegroup.
A clustered index and a table cannot be on different filegroups; therefore, the previous considerations apply only to nonclustered indexes.
Partitioned Tables on Separate Filegroups
In versions of SQL Server 2005 earlier than Service Pack 2 (SP2), DBCC CHECKFILEGROUP checks a partitioned table only if the entire table is on the specified filegroup. If the table is spread across multiple filegroups, the entire table is ignored. In SP2 and higher, when a partitioned table exists on multiple filegroups, DBCC CHECKFILEGROUP checks the partition rowsets that exist on the specified filegroup and ignores the rowsets in the other filegroups. Informational message 2594 indicates the partitions that were not checked. Nonclustered indexes not resident on the specified filegroup are not checked.
Understanding DBCC Error Messages
After the DBCC CHECKFILEGROUP command finishes, a message is written to the SQL Server error log. If the DBCC command successfully executes, the message indicates a successful completion and the amount of time that the command ran. If the DBCC command stops before completing the check because of an error, the message indicates the command was terminated, a state value, and the amount of time the command ran. The following table lists and describes the state values that can be included in the message.
Error number 8930 was raised. This indicates a metadata corruption that caused the DBCC command to terminate.
Error number 8967 was raised. There was an internal DBCC error.
A failure occurred during emergency mode database repair.
This indicates a metadata corruption that caused the DBCC command to terminate.
An assert or access violation was detected.
An unknown error occurred that terminated the DBCC command.
A mini-dump file (SQLDUMPnnnn.txt) is created in the SQL Server LOG directory whenever DBCC CHECKFILEGROUP detects a corruption error. When the Feature Usage data collection and Error Reporting features are enabled for the instance of SQL Server, the file is automatically forwarded to Microsoft. The collected data is used to improve SQL Server functionality.
The dump file contains the results of the DBCC CHECKFILEGROUP command and additional diagnostic output. The file has restricted discretionary access-control lists (DACLs). Access is limited to the SQL Server service account and members of the sysadmin role. By default, the sysadmin role contains all members of the Windows BUILTIN\Administrators group and the local administrator's group. The DBCC command does not fail if the data collection process fails.
If any errors are reported by DBCC CHECKFILEGROUP, we recommend restoring the database from the database backup. Note that repair options cannot be specified to DBCC CHECKFILEGROUP.
If no backup exists, running DBCC CHECKDB with a repair option specified corrects the errors reported. The repair option to use is specified at the end of the list if reported errors. Correcting the errors by using the REPAIR_ALLOW_DATA_LOSS option might require that some pages, and therefore data, be deleted.
DBCC CHECKFILEGROUP returns the following result set (values may vary):
Except when ESTIMATEONLY or NO_INFOMSGS is specified.
For the current database, if no database is specified, whether or not any options (except NOINDEX) are specified.
DBCC results for 'master'. DBCC results for 'sys.sysrowsetcolumns'. There are 630 rows in 7 pages for object 'sys.sysrowsetcolumns'. DBCC results for 'sys.sysrowsets'. There are 97 rows in 1 pages for object 'sys.sysrowsets'. DBCC results for 'sysallocunits'. There are 195 rows in 3 pages for object 'sysallocunits'. There are 2340 rows in 16 pages for object 'spt_values'. DBCC results for 'MSreplication_options'. There are 2 rows in 1 pages for object 'MSreplication_options'. CHECKFILEGROUP found 0 allocation errors and 0 consistency errors in database 'master'. DBCC execution completed. If DBCC printed error messages, contact your system administrator.
If NO_INFOMSGS is specified, DBCC CHECKFILEGROUP returns:
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
If ESTIMATEONLY is specified, DBCC CHECKFILEGROUP returns (values may vary):
Estimated TEMPDB space needed for CHECKALLOC (KB) ------------------------------------------------- 15 (1 row(s) affected) Estimated TEMPDB space needed for CHECKTABLES (KB) -------------------------------------------------- 207 (1 row(s) affected) DBCC execution completed. If DBCC printed error messages, contact your system administrator.
A. Checking the PRIMARY filegroup of a database
The following example checks the AdventureWorks2008R2 database primary filegroup.
B. Checking the PRIMARY filegroup without nonclustered indexes
The following example checks the AdventureWorks2008R2 database primary filegroup (excluding nonclustered indexes) by specifying the identification number of the primary filegroup, and by specifying NOINDEX.