| Lesson 7 |
Monitoring with the database consistency checker |
| Objective |
Monitor SQL Server with DBCC. |
Monitoring SQL Server with DBCC
DBCC historically stood for Database Consistency Checker, and that is still a fair description of its best-known command, DBCC CHECKDB. Microsoft's current documentation calls the whole family Database Console Commands instead, grouped into four categories: maintenance, miscellaneous, informational, and validation. Consistency checking is one job DBCC does, not the whole job, which matters for this lesson because several commands this course used to teach under the DBCC banner have since been deprecated in favor of Dynamic Management Views, the same pattern this module has already seen with sp_lock giving way to sys.dm_tran_locks.
That shift matters because this lesson, and the ones that follow it in this module, were originally written around a set of commands from a much older version of SQL Server. Treating all of them as equally current would mean teaching syntax that either no longer works meaningfully or has a documented, better-supported replacement. The approach this lesson takes instead: lead with what is genuinely still current, be explicit about what has been superseded and by what, and keep the historical commands visible only so they are recognizable rather than mistakenly treated as best practice.
DBCC CHECKDB: The Command That Matters Most
DBCC CHECKDB remains the command to actually know. It checks the logical and physical integrity of every object in a database. To run it:
- Start SQL Server Management Studio.
- Connect to the SQL Server instance you want to check.
- In Object Explorer, expand the Databases node and select the database to check.
- Right-click the database and select New > Query.
- In the query window, enter:
DBCC CHECKDB (database_name)
WITH NO_INFOMSGS, ALL_ERRORMSGS;
- Press F5 to execute.
NO_INFOMSGS suppresses routine informational messages so only actual problems surface;
ALL_ERRORMSGS ensures every error is returned rather than a truncated subset. A
PHYSICAL_ONLY option exists for a faster, lighter check limited to physical page and structural consistency, useful on very large databases where a full logical check is too expensive to run as often as would otherwise be ideal.
If DBCC CHECKDB finds corruption, repair options exist, REPAIR_REBUILD and REPAIR_ALLOW_DATA_LOSS among them, but REPAIR_ALLOW_DATA_LOSS can, as its name states plainly, lose data, and restoring from a known-good backup is the preferred fix whenever one is available. REPAIR_FAST is worth a specific mention: it still appears in the syntax for backward compatibility, but it no longer performs any repair action in current SQL Server versions, a detail easy to miss if you are working from an older reference.
DBCC CHECKDB can also be resource-intensive on a large database, which is why it is typically scheduled during a maintenance window via SQL Server Agent, covered in this module's first lesson, rather than run ad hoc during peak hours.
Reading the Output
A clean run ends with a summary stating the number of allocation and consistency errors found in each database object, ideally zero across the board. A problem typically surfaces as a numbered error message, messages in the 8900 range are common for allocation and consistency errors, paired with a description of the specific page, object, or index involved. NO_INFOMSGS keeps a clean run's output short, a single summary line, which makes a run that actually returns error messages stand out immediately rather than getting lost among routine status text.
A failed DBCC CHECKDB run is not, by itself, an instruction to immediately run a repair option. The first question is whether a recent, verified-good backup exists; if one does, restoring it is usually safer and more predictable than any in-place repair, since a repair operation can resolve consistency at the cost of removing the corrupted data entirely. Treat DBCC CHECKDB primarily as a detection tool, and treat backup and restore as the primary remediation path it exists to trigger.
A Historical Note: dbcc memusage
Earlier versions of this lesson covered
dbcc memusage as a live monitoring command. It is long deprecated. Microsoft's own documentation noted it was already reduced to near-uselessness by SQL Server 7.0, and current SQL Server versions direct memory investigation toward DMVs instead. For historical reference, its syntax and output looked like this:
dbcc memusage [('BUFFER')]
dbid objectid indexid buffers
------ ----------- ------- -----------
1 36 0 8
1 2 255 5
1 3 0 5
1 3 2 4
1 99 0 4
2 99 0 4
It reported the number of 8K memory buffers used by the twenty tables or indexes consuming the most memory:
dbid identified the database,
objectid the table,
indexid the index (zero meaning the space held data rather than an index), and
buffers the buffer count. The modern equivalent joins
sys.dm_os_buffer_descriptors against the catalog views to get the same per-object answer, with the current database rather than a hardcoded one:
SELECT OBJECT_NAME(p.object_id) AS table_name, COUNT(*) AS buffer_count
FROM sys.dm_os_buffer_descriptors AS bd
JOIN sys.allocation_units AS au
ON bd.allocation_unit_id = au.allocation_unit_id
JOIN sys.partitions AS p
ON au.container_id = p.hobt_id
WHERE bd.database_id = DB_ID()
GROUP BY p.object_id
ORDER BY buffer_count DESC;
For a broader question, not which tables hold the most buffer pool pages but what the server's memory as a whole is being spent on,
sys.dm_os_memory_clerks gives a breakdown by memory clerk type rather than by table:
SELECT TOP 10 type, name, pages_kb
FROM sys.dm_os_memory_clerks
ORDER BY pages_kb DESC;
Running the buffer descriptor query from above against an active database typically surfaces whichever tables are either large or heavily queried, the same information
dbcc memusage's twenty-row output once provided, but scoped to a specific database rather than a global top twenty, and joinable to any other catalog view rather than limited to the four fixed columns the old command returned.
A Historical Note: dbcc proccache
dbcc proccache is in the same position. It reported a single summary row describing the procedure cache:
| num proc buffs |
num proc buffs used |
num proc buffs active |
proc cache size |
proc cache used |
proc cache active |
| 40 |
40 |
13 |
48 |
48 |
21 |
num proc buffs was the maximum number of stored procedures that could fit in the procedure cache,
num proc buffs used the actual count cached, and
num proc buffs active the number currently executing;
proc cache size,
proc cache used, and
proc cache active reported the same three ideas in terms of cache buffers rather than procedure counts.
sys.dm_exec_cached_plans and
sys.dm_exec_query_stats now cover the same ground with far more detail, down to the individual plan rather than a single aggregate row:
SELECT COUNT(*) AS cached_plans,
SUM(size_in_bytes) / 1024 AS size_kb,
SUM(usecounts) AS total_uses
FROM sys.dm_exec_cached_plans;
Where
dbcc proccache reported a single aggregate row and left it there,
sys.dm_exec_cached_plans can be filtered and sorted to find the specific plans actually worth investigating, the least-reused plans taking up disproportionate space, for instance, or plans compiled repeatedly for what should be the same query, a sign of parameter sniffing or missing parameterization rather than anything the old command could have revealed on its own.
Neither
dbcc memusage nor
dbcc proccache should be presented as a current monitoring technique going forward in this course; they are documented here only so the terms are recognizable if encountered in old scripts or documentation, not as something to reach for when investigating a live SQL Server 2025 instance.
DBCC INPUTBUFFER and Its Modern Replacement
Choosing Between DBCC and the Rest of This Module
DBCC's role in this module is narrower than it might first appear, and it is worth being clear about where it actually fits next to everything else covered so far. sp_monitor, from the previous lesson, answers "how busy is this instance overall." Activity Monitor and sys.dm_tran_locks answer questions about specific sessions and locks. DBCC CHECKDB answers a different kind of question entirely: not how busy or how blocked, but whether the data itself is structurally sound. It is the one tool in this module aimed at integrity rather than performance, and nothing else covered so far substitutes for it; a database can show perfectly healthy wait statistics and connection counts while still harboring page-level corruption that only a consistency check will surface.
DBCC INPUTBUFFER and its modern DMV replacement sit closer to the session-level tools from earlier lessons, identifying what a specific session is doing, and are really an extension of that earlier coverage wearing a DBCC label rather than a distinct category of monitoring in their own right. dbcc memusage and dbcc proccache, for their part, occupied a space this module has already filled more thoroughly with sys.dm_os_memory_clerks, sys.dm_os_buffer_descriptors, and sys.dm_exec_cached_plans; there is no remaining gap in this module's coverage that only those two retired commands could fill.
Building This Into a Routine
Folded into the daily and weekly routine this module has been building, DBCC CHECKDB does not belong in the same quick daily pass as sp_monitor or Activity Monitor; it belongs on a schedule of its own, typically weekly, during a maintenance window, through a SQL Server Agent job. Pairing that job with Database Mail, as covered in this module's first lesson, so a failure actually generates an alert rather than sitting unread in a job history log, closes the loop between running the check and someone actually finding out it failed. DBCC INPUTBUFFER and sys.dm_exec_input_buffer, by contrast, are reach-for-it-when-needed tools, used in the moment during a live investigation into a specific session identified through sp_who or Activity Monitor, not something to run on a recurring schedule.
Limitations
DBCC's consistency-checking commands are not a complete monitoring solution on their own. DBCC CHECKDB can be resource-intensive, it cannot detect or repair every possible type of corruption, and it checks structural and logical integrity rather than performance in the way the DMVs and tools covered elsewhere in this module do.
Structural integrity is also a narrower guarantee than it might sound. DBCC CHECKDB confirms that pages, indexes, and allocation structures are internally consistent; it says nothing about whether the data itself is correct in a business sense. A row with the wrong value in a column, entered by a user or a buggy application, passes every consistency check DBCC CHECKDB runs, because nothing about it is structurally wrong. That kind of error is a data-quality problem, not a consistency problem, and no DBCC command in this module is the right tool for catching it.
For narrower checks than a full DBCC CHECKDB run, DBCC CHECKTABLE checks a single table rather than the whole database, and DBCC CHECKALLOC checks allocation structures specifically without the full logical check; both run faster and lighter when the question is scoped to a known area of concern rather than the database as a whole.
As this module's first lesson covered, dedicated third-party monitoring products exist for a more comprehensive, ongoing view of SQL Server health; DBCC is one piece of a monitoring routine, not a replacement for the rest of it, and the right tool for a given question is still whichever one in this module actually answers that specific question.
DBCC's Other Categories
This lesson has stayed inside DBCC's validation category, CHECKDB, CHECKTABLE, and CHECKALLOC among them, plus the informational-category commands this lesson has spent most of its time correcting. The other two categories exist too, even though they fall outside this lesson's monitoring focus. Maintenance commands change something rather than just reporting on it, DBCC SHRINKFILE being a well-known example, and miscellaneous commands cover everything that does not fit neatly elsewhere, DBCC FREEPROCCACHE, which clears the plan cache, among them. None of these are monitoring tools in the sense this module has used the word, but recognizing the category a given DBCC command falls into is a reasonable way to guess, correctly, whether a command you have not seen before reports on the server or changes it.
What's Ahead
Later lessons continue exploring DBCC commands for monitoring SQL Server's internals, including data cache monitoring next. Several of the specific commands this course originally slated for that coverage are, like the two addressed above, themselves deprecated, so that coverage will lean on their modern DMV equivalents rather than teaching retired syntax as current practice.
The pattern this lesson has followed, lead with what still works, name what has been replaced and by what, keep the old syntax visible only for recognition, is the same pattern worth carrying into those upcoming lessons. SQL Server's monitoring surface has moved almost entirely toward DMVs over the past two decades; DBCC's remaining relevance for monitoring purposes, outside of CHECKDB and its close relatives, is mostly historical at this point, and the lessons ahead should reflect that rather than presenting a 1990s-era command set as though it were still the primary way to look under the hood of a modern instance.