SDB407 Undocumented Tools and Trace Flags Paul S. Randal SQLskills.com Paul@SQLskills.

com

Author/Instructor: Paul S. Randal
• • Consultant/Trainer/Speaker/Author CEO, SQLskills.com
● ● ●

Email: Paul@SQLskills.com Blog: http://www.SQLskills.com/blogs/Paul Twitter: @PaulRandal

• • •

Contributing Editor of TechNet Magazine and SQL Server Magazine, author of the SQL Q&A columns, bi-monthly articles on DBA topics, multiple 2008 whitepapers 5 years at DEC responsible f th VMS fil t ibl for the file-system and check/repair t d h k/ i Almost 9 years as developer/manager in the SQL Storage Engine team through August 2007, ultimately responsible for Core Storage Engine

Wrote DBCC component, other Storage Engine code, DBCC CHECKDB/repair for SQL 2005

• • • •

Regular presenter at worldwide TechEds, SQL PASS and other conferences on disaster recovery, HA, maintenance, and internals Wrote and presented SQL Server 2008 training for Microsoft Course author/instructor for Microsoft Certified Master certs Co-Chair of the SQL Connections conference

Introduction
• There are a *ton* of undocumented tools, ton functions, stored-procedures and trace flags in SQL Server • Many of them are only there for testing or for deep debugging purposes for Product Support • Many of them are dangerous… • Many of them are *extremely* useful for DBAs

Overview
• DBCC commands • Functions and SPs • T Trace flags and startup options fl d t t ti

DBCC Commands (1)
• DBCC BUFFER
● ● ●

(dbname|id, objname|id, number of buffers to list, dump style, type of page) Lists the pages from the specified object that are in the buffer pool, from MRU to LRU order Can also be used WITH TABLERESULTS for later analysis (dbname, ‘repairindex’, objectid, indexid) Used to drop and recreate an index on a system table Can sometimes be used when only alternative is to extract data into a new database

• DBCC DBREPAIR
● ● ●

DBCC Commands (2)
• DBCC DBINFO
● ● ●

(dbname|id) Dumps the boot page contents for the database Equivalent to DBCC PAGE (dbname, 1 9 3) (dbname 1, 9, (dbname|id) Dumps all in-memory metadata about a database and its files (dbname|id, (dbname|id fileid) Dumps the file header page contents for the file Equivalent to DBCC PAGE (dbname, fileid, 0, 3)

• DBCC DBTABLE
● ●

• DBCC FILEHEADER
● ● ●

DBCC Commands (3)
• DBCC FLUSHPROCINDB
● ● ●

(dbid) Used to only free the proc cache for a single database Very useful for performance testing on production systems (dbname|id) Used to force all ghost records in a database to be cleaned up Very useful to reclaim space without having to do index rebuilds

• DBCC FORCEGHOSTCLEANUP
● ● ●

DBCC Commands (4)
• DBCC IND
● ● ●

(dbname|id, objectname|id, indexid|1|0|-1|-2, partitionid) Used to list all pages allocated to an object Indexid -1 means everything; -2 means just IAM pages 1 2 (dbname|id, fileid, pageid, dumpstyle) Used to dump a page contents Dumpstyle 1 means record hex dump; 2 means page hex dump; 3 means crack open records p (dbname|id) Used to examine VLF structure of transaction log

• DBCC PAGE
● ● ●

• DBCC LOGINFO
● ●

DBCC Commands (5)
• Persisting output from DBCC commands
● ●

Extremely useful for post-processing of results Allows consistency checking Agent j y g g jobs to easily y persist results

• Most DBCC commands support the undocumented WITH TABLERESULTS option S S

Undocumented because the output can change from release to release

Demo
Undocumented DBCC commands

Functions
• Lots of undocumented functions… • fn dblog fn_dblog
● ●

select * from fn_dblog (startLSN, endLSN) Used to dump the contents of the transaction log p g select * from fn_dblog (startLSN, endLSN, g( , , ‘DISK’|’TAPE’, devicenum, backuppath) Used to dump the contents of the transaction log in a backup

• fn_dump_dblog
● ●

Demo
Undocumented functions

Stored Procedures
• Lots of undocumented SPs and XPs… • sp MSforeachdb sp_MSforeachdb • sp_MSforeachtable

Operate per database and table – very useful Programmatically read the error log Useful for programmatically building restore paths, for instance

• xp_readerrorlog

• xp_regread

Inline Functions
• %%lockres%%
● ●

Used to get the lock resource hash value for a row when investigating incorrect blocking/deadlocking select *, %%lockres%% from t1 select *, %%rowdump%% from t1 Used to help find record locations when dealing with corruption select *, %%physloc%% %%physloc%%, sys.fn_PhysLocFormatter(%%physloc%%) from t1

• %%rowdump%%

• %%physloc%%
● ●

Demo
Undocumented inline functions

Startup Options (1)
• -E E
● ● ● ● ● ●

Lightly documented (http://support.microsoft.com/kb/329526) Changes the number of extents allocated by roundrobin allocation during index builds or rebuilds Use for data warehouses with very large index scans Increases the size of physical IOs to get better throughput g p 2005: 4 extents per file 2008+: 64 extents per file

Startup Options (2)
• -q”collation” q collation

Changes the server collation Remaps the file paths of the model database to be the same as the master database Allows the model database to be restored if the original location of model is unavailable This then allows tempdb to be created as it’s created created, it s from model Must use with T3608 to allow system database restore

• -Q Q
● ● ● ●

Trace Flags (1)
• • • • Literally *100s* of undocumented trace flags… y g Big (old) list: http://www.sqlservercentral.com/articles/trace+flags/70131/ Here are some useful ones 205

Log plan recompilations and reasons for them Disable ghost cleanup task Force page audits when pages are read from disk Protect P t t unchanged pages in th b ff pool t catch memory h d i the buffer l to t h corruptions

• 661

• 806

• 831

Trace Flags (2)
• 834

Enables large memory page support which can give a perf poost on large 64-bit systems
• See http://support.microsoft.com/kb/920093 p pp

• 1117

Force all data files to auto-grow at the same time Disable single-page allocations in tempdb
• See http://support.microsoft.com/kb/328551

• 1118

• 1211

Disable lock escalation Escalate locks only on memory pressure > 40%

• 1224

Trace Flags (3)
• 1462

Turns off database mirroring compression in 2008+ Turns off tracing calls to DBCC TRACEON/TRACEOFF Turns off tracing backup completions Fake NO_LOG/TRUNCATE_ONLY operations Extra auditing of log records

• 2505

• 3226

• 3231

• 3422

Trace Flags (4)
• 3502

Trace information about checkpoints Allow debug info to be printed to client or errorlog Allows attaching, detaching, and restoring ofsystem databases Trace user login information

• 3604/3605

• 3608

• 4013

Demo
Undocumented trace flags g

Review
• DBCC commands • Functions and SPs • Trace flags and startup options • All features I’ve described here are *safe* I ve safe • Make sure you try other undocumented stuff outr in test before using in production • Have fun!

Your Feedback is Important
Please fill out a session evaluation form drop it off at the conference registration desk. desk Thank Th k you! !

Sign up to vote on this title
UsefulNot useful