Maintenance DBCC Commands
From SQLServerPedia
|
See Also: Main_Page - Monitoring & Tuning - DBCC Commands
Maintenance DBCC CommandsMaintenance DBCC statements are used to gather information about the general health of the database as well as specific database objects and to repair minor database corruption issues.
This topic covers the following undocumented commands: LOGINFO, ERRORLOG, DBREINDEXALL and DETACHDB. DBCC LOGINFOThis command accepts a single optional parameter of either database name or database ID. DBCC LOGINFO returns information about virtual log files within the physical transaction log. If database name is not specified then information is returned about the current database. DBCC LOGINFO returns the following information:
The following is the example of results from DBCC LOGINFO: FileID FileSize StartOffset FSeqNo Status Parity CreateLSN 2 253952 8192 918829 0 128 0 2 253952 262144 918828 0 128 0 2 253952 516096 918827 0 64 0 2 278528 770048 918826 0 64 0 6 2555904 8192 918825 0 64 0 6 2555904 2564096 918824 0 64 916687000000037000000 6 2555904 5120000 918835 2 128 916688000000072000000 6 2809856 7675904 918834 2 128 916690000000008000000 7 2555904 8192 918833 2 64 916691000000037000000 7 2555904 2564096 918832 0 64 916692000000060000000 The status column of DBCC LOGINFO's output is perhaps the most useful bit of information. If this column contains zero, then the transaction log files can be shrunk. If this column contains 2, then there is no room for shrinking the transaction log since the last virtual log file contains active transactions. DBCC ERRORLOGThis statement takes no parameters and is used to reinitialize the SQL Server error log. If you restart SQL Server frequently, you might have noticed that SQL Server reinitializes the error log each time it is started. However, if your log grows beyond 1 million bytes, it takes a considerable amount of time to open the log. As a database administrator you want to have access to the log at all times. Therefore if the error log tends to grow fast, be sure to execute this command regularly. DBCC DBREINDEXALLThis command is identical to <a href="DBM3#B11">DBCC DBREINDEX]] except that it rebuilds all indexes within the specified database. You can supply a database name or ID as the parameter, as in DBCC DBREINDEXALL('pubs'). DBCC DETACHDBAlthough undocumented, this command is used by the sp_detach_db system procedure to detach a particular database from the current instance of SQL Server. The database name must be in single quotes. |