s Monitor SQL Server 2025 with Trace Flags


Monitoring SQL  «Prev  Next»

Lesson 10 SQL Server 2025, Trace Flags
Objective Monitor SQL Server 2025 using trace flags

Monitor SQL Server 2025 with Trace Flags

Trace flags are numbered switches that temporarily change SQL Server's default behavior, typically for diagnostics or compatibility rather than for ordinary configuration. A flag is identified purely by number, there is no name attached to it the way there is for a configuration option or a DMV, and it is turned on, turned off, or checked using a small family of dbcc commands rather than through SSMS's graphical settings. Unlike the handful of commands retired two lessons ago, dbcc traceon, dbcc traceoff, and dbcc tracestatus are still documented, current, and fully supported in SQL Server 2025.

This lesson covers only the trace flags most relevant to monitoring; many others exist for query optimizer behavior, backward compatibility with older application code, and other purposes outside this module's scope. In SQL Server 2025, Extended Events (including the built-in system_health session), Query Store, and the Dynamic Management Views and Functions covered in the previous lesson handle most ongoing monitoring. Trace flags remain useful for a smaller, more specific set of diagnostic and compatibility needs, which is exactly why this lesson is short relative to the four-tool lesson that preceded it rather than an attempt to compete with it.

Trace Flags Useful for Monitoring

-1 Not a flag itself, but an argument to dbcc traceon or dbcc traceoff that applies the change to every connection on the instance rather than just the current session.
1204 When a deadlock[1] occurs, writes information about the locks and resources participating in it to the error log.
1222 Writes the same deadlock information in a more detailed, XML-formatted form. Preferred over 1204 for deadlock diagnostics whenever error-log output specifically is what's wanted.
3226 Suppresses the routine "backup succeeded" messages that otherwise fill the error log after every successful backup. Commonly set as a startup flag rather than toggled during a session.
3604 Sends trace and DBCC output to the client that issued the command, rather than to the error log.
3605 Sends trace and DBCC output to the error log, rather than to the client.

Prefer Extended Events for Deadlock Diagnostics

1204 and 1222 remain the trace flags most commonly cited for monitoring deadlocks, and both still work exactly as documented. But the built-in system_health Extended Events session, introduced in the previous lesson, already captures full deadlock graphs continuously, with lower overhead than either flag, and with nothing to remember to turn on beforehand. A deadlock that already happened yesterday is sitting in system_health's captured data right now; it was never sitting in the error log unless 1204 or 1222 happened to already be on at the time.

The custom LockMonitoring Extended Events session built earlier in this module, capturing lock_acquired, lock_timeout, and lock_deadlock events into a file target, covers this same ground with a purpose-built session rather than a system default. Between the two, reach for system_health first, since it is already running and requires no setup, and build a custom session like LockMonitoring only when a narrower scope, a single database, a longer retention window, or extra captured actions, is specifically needed. Reach for 1204 or 1222 only when error-log output specifically, rather than either Extended Events target, is the actual requirement, for instance when a monitoring script already parses the error log for other reasons and adding one more pattern to watch for is simpler than standing up a new Extended Events consumer.

It is worth being explicit that Query Store, covered in the previous lesson alongside Extended Events, does not fill this particular gap. Query Store tracks query text, execution plans, and runtime statistics; it has no deadlock graph and no equivalent of a deadlock event, because a deadlock victim's query, by definition, never finished executing and so never produced the runtime statistics Query Store records. Anyone expecting Query Store's history to already contain the deadlock that happened at 2 a.m. last night will come up empty; that history lives in system_health, a custom Extended Events session, or, as a fallback, the error log via 1204 or 1222, never in Query Store's catalog views.

Controlling Trace Flags: DBCC TRACEON, TRACEOFF, and TRACESTATUS

dbcc traceon

The dbcc traceon command turns one or more flags on after SQL Server has already started. The syntax is as follows:
dbcc traceon (flag [, flag ...] [, -1])
Without the -1 argument, the flag is turned on only for the current connection, and turns back off automatically when that connection closes. This session-scoped behavior is easy to overlook: a flag turned on to investigate a problem in one query window will appear to have "stopped working" the moment that window is closed and a new one opened, when in fact it simply never applied globally in the first place.

It is worth being precise about what -1 actually does here, since "global" turns out to mean two different things depending on how a flag was turned on. A flag turned on with dbcc traceon (flag, -1) applies to every connection on the instance starting immediately, but that effect does not survive a service restart; the next time SQL Server starts, the flag is off again unless it was also added as a -T#### startup parameter. A flag added only as a startup parameter, by contrast, persists across restarts but was never turned on by dbcc traceon at all, so dbcc tracestatus run before the next restart may not show it as a currently running change in the same way. The two mechanisms, immediate global toggle versus persistent startup configuration, solve different problems and are worth keeping separate in practice rather than treated as interchangeable ways of saying "turn this on for everyone."

dbcc traceoff

The dbcc traceoff command turns one or more flags off, using the identical syntax:
dbcc traceoff (flag [, flag ...] [, -1])
As with traceon, omitting -1 here turns the flag off only for the current connection; a flag that was turned on globally with -1 needs -1 again to turn it off globally, rather than being cleared by a plain dbcc traceoff issued from a different session.

dbcc tracestatus

The dbcc tracestatus command reports whether a flag is currently on or off, for one flag, several, or, with no flag numbers at all, every flag currently set on the connection:
dbcc tracestatus ([flag [, flag ...]] [, -1])
For each flag passed in, SQL Server reports whether it is on (1) or off (0). Sample output, checking four flags at once:
TraceFlag   Status
---------   ------
3604        1
1222        1
3226        0
1204        0
This output shows 3604 and 1222 currently on, and 3226 and 1204 currently off, exactly the kind of quick before-and-after check worth running immediately before and after toggling a flag to confirm the change actually took effect at the intended scope.

Starting Trace Flags Automatically

A trace flag can also be configured to turn on automatically every time the SQL Server service starts, by adding a -T#### startup parameter (an uppercase T, followed immediately by the flag number) to the service's startup configuration. Multiple -T#### parameters can be added for multiple flags, and a flag set this way behaves as though dbcc traceon had already been run with the -1 argument the moment the service finished starting.

In SQL Server 2025, most ongoing monitoring is better handled by Extended Events, Query Store, and DMVs/DMFs than by leaving many trace flags permanently enabled at startup. A startup trace flag is best reserved for a small, specific, well-understood need, such as 3226's log suppression, rather than used as a general-purpose monitoring mechanism; a startup configuration carrying a dozen trace flags accumulated over the years, with nobody quite certain why half of them are there, is a common and avoidable source of confusion during later troubleshooting.

Startup parameters themselves are set through SQL Server Configuration Manager rather than through T-SQL: open the properties of the SQL Server service, find the Startup Parameters tab, and add the -T#### entry there. The change does not take effect until the service is restarted, which matters when the flag being added is meant to address a problem happening right now; adding it to the startup parameters is the way to make the change permanent, but dbcc traceon with -1 is still the way to apply it immediately without waiting for a restart window. A common, reasonable pattern is to apply a flag immediately with dbcc traceon to confirm it actually addresses the problem, and only then add it to the startup parameters once it has proven useful, rather than committing to a permanent change on a hunch.

Trace Flags Alongside the Rest of This Module's Tools

It is worth placing trace flags alongside everything else this module has covered, since on their own they can look like an odd, disconnected feature: a handful of numbered switches with no obvious relationship to sp_monitor, Activity Monitor, DMVs, Query Store, or Extended Events. The relationship is actually fairly direct. sp_monitor and the DMVs covered earlier report state; trace flags change behavior. A DMV like sys.dm_tran_locks can be queried to see what is locked right now, but nothing about querying it changes how SQL Server handles the next deadlock; trace flag 1222, by contrast, changes what SQL Server writes to the error log the next time a deadlock actually occurs. Query Store and Extended Events sit closer to trace flags in this respect, since both can also be described as changing what SQL Server captures going forward, but they do so through a structured session or a catalog of views rather than through a bare numbered switch with no further configuration surface.

The practical overlap is narrower than the conceptual one. For deadlocks specifically, this lesson has already made the case that system_health or a custom Extended Events session should be reached for before 1204 or 1222. For most other monitoring needs covered elsewhere in this module, buffer cache behavior, overall system load, query performance history, lock contention, there is no trace flag equivalent at all; those are DMV, Query Store, and Extended Events territory exclusively, and no amount of searching through trace flag reference lists will turn up a flag for "show me the current buffer cache hit ratio," because that was never what trace flags were for.

When a Trace Flag Is Still the Right Tool

Three situations still call for a trace flag over any of this module's other tools. The first is error-log noise reduction, 3226 being the standing example, where the goal is not to observe anything new but to stop a routine, uninteresting message from obscuring the log. The second is controlling where diagnostic output goes, 3604 versus 3605, which matters specifically when running an interactive dbcc command and needing its output in the current query window rather than buried in the error log, or vice versa when a script needs the error log to carry the result for a later automated check. The third is compatibility and diagnostic flags outside this lesson's scope entirely, version-specific behavior switches that Microsoft documents on a flag-by-flag basis and that have no DMV, Query Store, or Extended Events equivalent because they are not reporting anything, they are changing how a specific internal behavior works.

A useful habit, given all of this, is to default to checking whether a monitoring question is actually a trace-flag question at all before reaching for one. If the goal is to see something that is currently happening or has already happened, a DMV, Query Store, or Extended Events session is almost always the better fit, as this lesson and the one before it have both argued. If the goal is instead to change what gets written somewhere, or to suppress something that already gets written, a trace flag is often the simplest tool available, and reaching past it for a heavier Extended Events session to solve a one-line log-suppression problem would be the wrong kind of modernization, swapping a perfectly good simple tool for a more complex one that happens to be newer.

A short worked comparison makes the difference concrete. A DBA noticing the error log filling with repeated "backup succeeded" messages has, in principle, several tools available: an Extended Events session filtering for backup-completion events, a scheduled job that scans and trims the error log, or trace flag 3226 set once at startup. The first two both work, but both require building and maintaining something, a session definition in one case, a scheduled cleanup script in the other, to solve a problem that 3226 solves with a single startup parameter and no ongoing maintenance at all. This is the pattern worth internalizing from the whole lesson: newer is not automatically better, and the right question is always which tool solves this specific problem with the least remaining complexity, not which tool is most recently introduced.

Building This Into a Routine

In practice, trace flags earn a place in a monitoring routine mostly at the edges of it rather than at the center. 3226 is worth setting once, as a startup flag, on any instance where backup jobs run frequently enough that their success messages are crowding out everything else in the error log, and then forgetting about; it is not something to revisit on a regular cadence. 1204 and 1222 are worth knowing about for the rare case where a deadlock needs to be correlated against error-log timestamps already being monitored by some other system, but for the day-to-day work of actually investigating deadlock patterns, the system_health session or a purpose-built Extended Events session covered earlier in this module should be the first and usually only stop. 3604 and 3605 come up situationally, almost always while actively running a dbcc command by hand during an investigation, rather than as something configured once and left alone.

The broader lesson, carried over from the previous one, holds here too: a numbered switch from an older era of SQL Server is not automatically obsolete just because a newer, more structured tool now covers similar ground. Trace flags earned their place in this module not through nostalgia, but because a handful of them, verified individually against what SQL Server 2025 actually documents, still do a specific job better or more simply than anything newer does.

That verification step matters more than it might seem. The previous lesson in this module existed specifically because an entire family of commands, DBCC PERFMON, dbcc outputbuffer, and dbcc inputbuffer among them, had quietly stopped being documented anywhere while still technically running, which is exactly the kind of gap that lets outdated advice persist for years after it should have been retired. The six trace flags covered in this lesson were checked individually against current documentation before being kept rather than assumed safe simply because they had appeared on this page since 2013; the difference between this lesson surviving mostly intact and the previous one being rebuilt from the ground up is that difference in verification outcome, not a difference in how carefully each was reviewed.
[1]Deadlock: when two or more sessions each hold locks on resources that the other needs, creating a cycle. SQL Server chooses one session as the victim and rolls it back.

SEMrush Software 10 SEMrush Banner 10