3. documented and undocumented
• Documented
• support
• Books Online
• Microsoft Knowledgebase
• Whitepapers
• Undocumented
• unsupported & risky
• Blog
• internet
• user group presentations
• do not expect me (or Microsoft) to help you with any issue
caused by running any unsupported piece of code on your SQL
Server!
8. Trace Flags
• Trace flags are used to temporarily set specific server
characteristics or to switch off a particular behavior. For
example, if trace flag 3205 is set when an instance of SQL Server
starts, hardware compression for tape drivers is disabled. Trace
flags are frequently used to diagnose performance issues or to
debug stored procedures or complex computer systems.
BOL:
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/b971b540-1ac2-
435b-b191-24399eb88265.htm
9. Trace Flags vs. DBCC
Trace Flags:
• Trace Flags are numbers
• Toggle on/off to change in SQL Server‟s behavior
• Trace Flags toggle by DBCC (DBCC TRACEON / TRACEOFF)
• Result is change in SQL Server‟s behavior
• Could be just to enable a hotfix (multi HF in the same build)
DBCCs
• DBCCs are text command
• Result is a report as messages uotput
10. DBCC TRACEON
• --switching on trace flag 3205. This flag is switched on only for
the current connection
• DBCC TRACEON (3205);
• GO
• --switches on trace flag 3205 globally
• DBCC TRACEON (3205, -1);
• GO
• --switches on trace flags 3205, and 260 globally
• DBCC TRACEON (3205, 260, -1);
• GO
11. DBCC TRACEOFF
• --disables trace flag 3205
• DBCC TRACEOFF (3205);
• GO
• --disables trace flag 3205 globally
• DBCC TRACEOFF (3205, -1);
• GO
• --sdisables trace flags 3205 and 260 globally.
• DBCC TRACEOFF (3205, 260, -1);
• GO
12. DBCC TRACESTATUS
• Status - Indicates whether the trace flag is set ON of OFF, either
globally or for the session.
1 = ON / 0 = OFF
• Global - Indicates whether the trace flag is set globally.
1 = True / 0 = False
• Session - Indicates whether the trace flag is set for the session
1 = True / 0 = False
13. DBCC TRACESTATUS
--displays the status of all trace flags that are currently enabled
globally.
DBCC TRACESTATUS(-1);
GO
--displays the status of trace flags 2528 and 3205.
DBCC TRACESTATUS (2528, 3205);
GO
--displays whether trace flag 3205 is enabled globally.
DBCC TRACESTATUS (3205, -1);
GO
--lists all the trace flags that are enabled for the current session.
DBCC TRACESTATUS();
GO
14. Startup parameters
• http://msdn.microsoft.com/en-us/library/ms345416.aspx How to:
Configure Server Startup Options (SQL Server Configuration
Manager)
•
On a cluster, changes must be made on the active server while SQL Server is
online, and will take effect when the Database Engine is restarted. The registry
update of the startup options on the other node will occur upon the next
failover.
18. And if the IT is not your friend?
• sp_procoption - Sets stored procedure for autoexecution. A
stored procedure that is set to autoexecution runs every time an
instance of SQL Server is started.
CREATE PROC TraceOnAtBoot
AS
DBCC TRACEON (1234,-1);
DBCC TRACEON (5678,-1);
GO
• EXEC sp_procoption „TraceOnAtBoot‟, 'autostart', 'TRUE'
19. Note
•Trace flag behavior may not
be supported in future
releases of SQL Server
• BOL & http://msdn.microsoft.com/en-us/library/ms188396.aspx
20. My Application
• 8,640,000 up to 60,480,000 rows in single table
• 500-3,000 new rows per secund
• Each row around 120K (20 MetaData + 100K image)
• From 300 TB through 1 PB up to 4 PB
• http://support.microsoft.com/kb/920093
Tuning options for SQL Server 2005 and SQL Server 2008 when
running in high performance workloads
21. 652: Disable page pre-fetching scans
• SQL Server no longer brings database pages into the buffer pool
before these database pages are consumed by the scans.
• Queries that benefit from the page pre-fetching feature exhibit
low performance.
23. 661: Disable the ghost record removal process
• A ghost record is the result of a delete
operation.
After deleting the deleted record is kept as a
ghost record.
Later, the deleted record is purged by the
ghost record removal process.
24. 834: Use Microsoft Windows large-page
allocations for the buffer pool (SQL 2005)
• Page memory size may be from 2 MB to 16 MB.
• Trace flag 834 causes SQL Server to use Microsoft
Windows large-page allocations for the memory that is
allocated for the buffer pool.
• applies only to 64-bit versions of SQL Server.
• May prevent the server from starting if memory is
fragmented and if large pages cannot be allocated.
Therefore, trace flag 834 is best suited for servers that
are dedicated to SQL Server.
• Automatically in SQL 2008
25. 836: Use the max server memory option for the
buffer pool
• Causes SQL Server to size the buffer pool at
startup based on the value of the max server
memory option instead of based on the total
physical memory.
• Trace flag 836 applies only to 32-bit versions
of SQL Server that have the AWE allocation
enabled. You can turn on trace flag 836 only at
startup.
26.
27. TF in this doc (is it really help me?)
• Trace flag 652: Disable page pre-fetching scans
• Trace flag 661: Disable the ghost record removal process
• Trace flag 834: Use Microsoft Windows large-page allocations for the
buffer pool
• Trace flag 836: Use the max server memory option for the buffer pool
• Trace flag 2301: Enable advanced decision support optimizations
• Trace flags that disable various ring buffers
• Trace flag 8011: Disable the ring buffer for Resource Monitor
• Trace flag 8012: Disable the ring buffer for schedulers
• Trace flag 8018: Disable the exception ring bufferTrace flag 8019: Disable
stack collection for the exception ring buffer
• Trace flag 8020: Disable working set monitoring
• Trace flag 8744: Disable pre-fetching for ranges
28. Still need to
• How to Load Lots of Data?
• Avoid Lock Escalation
• Partitions Tables
• Auto Grow Equally in all Data file
• Deadlocks
• TempDB
• BackUP
• Query processor
29. How to Load Lots of Data?
• http://msdn.microsoft.com/en-
us/library/dd425070(v=sql.100).aspx The Data
Loading Performance Guide (Thomas Kejser, Peter
Carlin and Stuart Ozer )
• SQL Server 2008 introduces trace flag 610, which
controls minimally logged inserts into indexed tables
• http://blogs.msdn.com/b/sqlserverstorageengine/archi
ve/2008/10/24/new-update-on-minimal-logging-for-sql-
server-2008.aspx MSDN Blogs > SQL Server Storage
Engine > New update on minimal logging for SQL
Server 2008
30. 1211: Avoid Lock Escalation
• Lock escalation to table level may occur as the number of row-
level exclusive (X) locks rises above a threshold. If this
happens, concurrency will drop to single threaded inserts. It is
possible to prevent this escalation from happening; the technique
depends on the SQL Server version:
• For SQL Server 2005, lock escalation generally
occurs at 5000 locked allocated. There are
exceptions. See this
• Setting a BATCHSIZE to a number lower than this will disable
escalation
• Alternatively, you can use trace flag 1211 to completely
disable lock escalation on the server.
• For SQL Server 2008, it is also possible to completely
disable lock escalation on a table level.
31. 1224: Avoid Lock Escalation
• Similar to trace flag 1211 with one key
difference. It enables lock escalation when
lock manager acquires 40% of the statically
allocated memory or (40%) non-AWE(32-
bit)/regular(64-bit) dynamically allocated
memory
• If this memory cannot be allocated due to
other components taking up more
memory, the lock escalation can be triggered
earlier.
• If both trace flags (1211 and 1224) are set at
the same time, the trace flag 1211 takes
precedence.
32. 1117: Auto Grow Equally in all Data file
• From Performance aspect all data file should be in
same size.
• Otherwise, SQL Server will utilize the data file which
is largest in size, assume you have auto growth option
enabled then obviously that file will grow and SQL
Server will keep on using the data file which is largest
in size.
• TF 1117 Attempt to grow all files in one filegroup
and not just the one next in the autogrowth chain .
•
Read more: http://sql-
articles.com/articles/general/day-6trace-flag-1117-
auto-grow-equally-in-all-data-file/#ixzz1lRHA9AZ7
34. 1204, 1205, 1222: Deadlock
• Scope: global only
• TF1204 Returns the resources and types of locks
participating in a deadlock and also the current
command affected
• TF1205 (undocumented) startup parameter collects
information every time that the deadlock algorithm
checks for a deadlock, not when a deadlock is
encountered, was documented in SQL Server 7.0
BOL, but is not documented in SQL Server 2008.
• TF 1222 formats deadlock information, first by
processes and then by resources. It is possible to
enable 1204 and 12222 trace flags to obtain two
representations of the same deadlock event.
35. 1204 Note
• In SQL Server 2000, a simple DBCC TRACEON (1204) is
enough to enable deadlock reporting to the error log.
• In SQL Server 2008, you must enable the flag globally because
the session-level flag is not visible to the deadlock monitor
thread.
37. 1118: TempDB
• “Nothing Is Not More Permanent Than The
Temporary” - Wonder TempDB , Dubi Lebel ISUG
Nov 09
• Slide 38, KB 328551 , TF 1118 reduce the allocation
resource contention for tempdb that is experiencing
heavy usage.
• directs SQL Server to allocate full extents to each
tempdb objects (instead of mixed extents)
• http://technet.microsoft.com/en-us/library/cc966545.aspx ,
38. 3226: prevents successful back
operations from being logged
• By default, every successful backup operation adds
an entry in the SQL Server error log and in the system
event log.
• If you create very frequent log backups, these success
messages accumulate quickly, resulting in huge error
logs in which finding other messages is problematic.
39. 3014: More information on Backup
• undocumented
• returns more information to the ERRORLOG about
BACKUP.
40. 3004: More More information on Backup
• undocumented
• returns more information to the ERRORLOG about
BACKUP include Creation the backup file or
Padding to the backup file.
41. All about backup
•“It's just simple being in simplicity or
It's not folly to be in full”
ISUG Dubi Lebel ISUG May 12
43. 4199 : Query processor
• KB 974006
• added in Cumulative Update 6 for SQL Server 2005 Service
Pack 3 (SP3), Cumulative Update package 7 for SQL Server
2008, Cumulative Update 7 for SQL Server 2008 Service Pack
1 (SP1), and SQL Server 2008 R2.
• Because of the policy change to put query processor fixes under
a trace flag, even if you are running with the latest hotfix or
cumulative update installed, you are not necessarily running SQL
Server with all the latest query processor fixes enabled.
• TF 4199 enable all the fixes that were previously made for the
query processor under many trace flags. In addition, all future
query processor fixes will be controlled by using this trace flag.
44. 3502: Prints a message to the log at
the start and end of each checkpoint.
47. more
• Trace flag 2528 disables parallel checking of objects during
DBCC CHECKDB, DBCC CHECKFILEGROUP and DBCC
CHECKTABL
48. More Important UDTF
• 8602 Ignore index hints that are spe-cified in query/procedure.
• 8722 Dis-able all other types of hints. This includes the OPTION
clause.
• 8755 Dis-able any lock-ing hints like READONLY. By set-ting
this, you allow SQL Server to dynam-ic-ally select the best
lock-ing hint for the query.
"DBCC documented and undocumented, useful or un-useful"There are a lot of undocumented DBCC in SQL Server, some of them for developer debugging, other for testing small set are for Support engineers but... Many of them could be useful for DBAs and many of them are dangerous…in part 1- 'the introduction' we will try to answer: how to find those DBCCs? how to find minimal official documented? and how to use them?part 2-'when and what undocumented should I use' will deal with DBCC that can help us like the DBCC CORRUPT(dbname|dbid)
--SET NOCOUNT ON--GO--IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[test]') AND type in (N'U'))--DROP TABLE [dbo].[test]--GO--CREATE TABLE [dbo].[test](-- [i] [int] NOT NULL,-- [j] [int] NOT NULL,-- [d] [datetime2](7) NULL,-- [FFU_FHR] [char](5000) DEFAULT 'some default st' NOT NULL--) ON [PRIMARY]--GO--CREATE CLUSTERED INDEX [cix_test] ON [dbo].[test] --(-- [i] ASC)--GO--DECLARE @i INT = 0--WHILE @i < 20000--BEGIN-- INSERT test(i, j, d) -- SELECT @i, -- CASE WHEN @i % 2 = 0 THEN @i ELSE 2000000 - @i END,-- SYSDATETIME()--END--GODBCC TRACESTATUS GOSET STATISTICS IO ONGOselect 'Starting', cast (SYSDATETIME() as time)GODBCC DROPCLEANBUFFERS; GO SELECT MAX(d) FROM test;GOselect 'Without TF ', cast (SYSDATETIME() as time)GODBCC TRACEON(-1, 652) DBCC DROPCLEANBUFFERS; GO SELECT MAX(d) FROM test;GODBCC TRACEOFF (-1, 652) GOselect 'with TF', cast (SYSDATETIME() as time)GO
Set NoCount OnGO--DBCC TRACEON (1117,-1)--GO--Create database with 4 files keeping unequal size USE master GO IF EXISTS(SELECT 1 FROM sys.databases where name='1117') DROP DATABASE [1117] GO CREATE DATABASE [1117] ON PRIMARY( NAME = N'1117', FILENAME = N'C:\\MSSQL\\DATA\\1117.mdf', SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), -- first Data file 3 MB( NAME = N'1117_1', FILENAME = N'C:\\MSSQL\\DATA\\1117_1.ndf', SIZE = 1024KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), -- all other files only 1 MB( NAME = N'1117_2', FILENAME = N'C:\\MSSQL\\DATA\\1117_2.ndf', SIZE = 1024KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ), ( NAME = N'1117_3', FILENAME = N'C:\\MSSQL\\DATA\\1117_3.ndf', SIZE = 1024KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON( NAME = N'1117_log', FILENAME = N'C:\\MSSQL\\DATA\\1117_log.ldf', SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) GO --script to get file size initially --SELECT name, (size*8)/1024 'Size in MB' FROM [1117].sys.database_filesSELECT file_id, name, [sizeInMb] = CONVERT(DECIMAL(12,2),ROUND(size/128.000,2)), [spaceUsedMb] = CONVERT(DECIMAL(12,2),ROUND(FILEPROPERTY(name,'SPACEUSED')/128.000,2)) FROM [1117].sys.database_filesWHERE (data_space_id = 1)---=-=-=-=-=-=-=-=-=-=-=--Now CREATE a table to populate the data USE [1117] GO CREATE TABLE Trash (name CHAR(8000)) GO INSERT Trash VALUES ('Trash for TF 1117') GO 700 --script to get file size after data insertion --SELECT name, (size*8)/1024 'Size in MB' FROM [1117].sys.database_filesSELECT file_id, name, [sizeInMb] = CONVERT(DECIMAL(12,2),ROUND(size/128.000,2)), [spaceUsedMb] = CONVERT(DECIMAL(12,2),ROUND(FILEPROPERTY(name,'SPACEUSED')/128.000,2)) FROM [1117].sys.database_filesWHERE (data_space_id = 1)GO ----INSERT Trash VALUES ('Trash for TF 1117') GO 200 SELECT file_id, name, [sizeInMb] = CONVERT(DECIMAL(12,2),ROUND(size/128.000,2)), [spaceUsedMb] = CONVERT(DECIMAL(12,2),ROUND(FILEPROPERTY(name,'SPACEUSED')/128.000,2)) FROM [1117].sys.database_filesWHERE (data_space_id = 1)--DBCC TRACEOFF (1117,-1)--GO
Set NoCount OnGOdbcctracestatusGOUSE DBCC_DEMOGOUSE [DBCC_DEMO]GOIF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DL_1]') AND type in (N'U'))DROP TABLE [dbo].[DL_1]GOCREATE TABLE [dbo].[DL_1]( [i] [int] NULL, [c] [char](10) NULL) ON [PRIMARY]GOIF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DL_2]') AND type in (N'U'))DROP TABLE [dbo].[DL_2]GOCREATE TABLE [dbo].[DL_2]( [i] [int] NULL, [c] [char](10) NULL) ON [PRIMARY]GO--OPEN Secund TABinsert DL_1 values(1,'abc')GO------=-=-=-=-=-=-=Begin tranupdate DL_1 set c='efg'where i =1--UPADTE in Sec tabupdate DL_2 set c='Def'where i =2---rollback tranDBCC TRACEON(1204, 3605,-1)DBCC TRACEOff(1204,1205,1222, 3605,-1)DBCC TRACEON(1205, 3605,-1)DBCC TRACEON(1222, 3605,-1)exec sp_readerrorlog-----------------------------Set NoCount OnGOinsert DL_2 values(2,'abc')GO---Begin tranupdate DL_2 set c='efg'where i =2----update DL_1 set c='efg'where i =1----rollback tranEXEC sp_cycle_errorlog ; GODBCC TRACEON(1204, 3605,-1)DBCC TRACEOff(1204,1205, 3605,-1)DBCC TRACEON(1205, 3605,-1)DBCC TRACEON(1222, 3605,-1)exec sp_readerrorlog
Set NoCount OnGOuse master;GODBCC TRACEON(3004,--3014,3604,3605,-1);GORESTORE DATABASE [AdventureWorks2008R2] FROM DISK = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.VULCAN\\MSSQL\\Backup\\AdventureWorks2008R2.bak' WITH FILE = 1, NOUNLOAD, STATS = 10GODBCC TRACEOFF(3004,3014,3604,3605,-1);--DBCC tracestatus()--sp_readerrorlogDBCC TRACEON(3004,3014,3604,3605,-1);create database ttt;EXEC sp_readerrorlog; drop database ttt;EXEC sp_readerrorlog;DBCC TRACEOFF(3004,3014,3604,3605,-1);
Set NoCount OnGODBCC tracestatusDBCC traceon(3502,3604,3605,-1)CHECKPOINT exec sp_readerrorlogDBCC traceoff(3502,3604,3605,-1)