Author/Instructor: Paul S. RandalAuthor/Instructor: Paul S. Randal
• Consultant/Trainer/Speaker/Author• CEO, SQLskills.com
● Email: [email protected]● Blog: http://www.SQLskills.com/blogs/Paul● 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 whitepapers5 t DEC ibl f th VMS fil t d h k/ i• 5 years at DEC responsible for the VMS file-system and check/repair
• 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• Course author/instructor for Microsoft Certified Master certs• Co-Chair of the SQL Connections conference
IntroductionIntroduction
• There are a *ton* of undocumented tools,There are a ton of undocumented tools, 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
OverviewOverview
• DBCC commandsDBCC commands• Functions and SPs
T fl d t t ti• Trace flags and startup options
DBCC Commands (1)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● 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
DBCC DBREPAIR• DBCC DBREPAIR● (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 Commands (2)DBCC Commands (2)
• DBCC DBINFO● (dbname|id)● Dumps the boot page contents for the database
Equivalent to DBCC PAGE (dbname 1 9 3)● Equivalent to DBCC PAGE (dbname, 1, 9, 3)
• DBCC DBTABLE● (dbname|id)● Dumps all in-memory metadata about a database and its files
• DBCC FILEHEADER(dbname|id fileid)● (dbname|id, fileid)
● Dumps the file header page contents for the file● Equivalent to DBCC PAGE (dbname, fileid, 0, 3)
DBCC Commands (3)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● Very useful for performance testing on production systems
• DBCC FORCEGHOSTCLEANUP● (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 Commands (4)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● Indexid -1 means everything; -2 means just IAM pages
• DBCC PAGE● (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 recordsp
• DBCC LOGINFO● (dbname|id)● Used to examine VLF structure of transaction log
DBCC Commands (5)DBCC Commands (5)
• Persisting output from DBCC commandsPersisting output from DBCC commands● Extremely useful for post-processing of results● Allows consistency checking Agent jobs to easily y g g j y
persist results• Most DBCC commands support the
S Sundocumented WITH TABLERESULTS option● Undocumented because the output can change from
release to releaserelease to release
Demo
Undocumented DBCC commands
FunctionsFunctions
• Lots of undocumented functions…Lots of undocumented functions…
• fn dblogfn_dblog● select * from fn_dblog (startLSN, endLSN)● Used to dump the contents of the transaction logp g
• fn_dump_dblog● select * from fn dblog (startLSN, endLSN, _ g ( , ,
‘DISK’|’TAPE’, devicenum, backuppath)● Used to dump the contents of the transaction log in a
backupbackup
Demo
Undocumented functions
Stored ProceduresStored Procedures
• Lots of undocumented SPs and XPs…Lots of undocumented SPs and XPs…
• sp MSforeachdbsp_MSforeachdb• sp_MSforeachtable
● Operate per database and table – very useful● Operate per database and table very useful• xp_readerrorlog
● Programmatically read the error log● Programmatically read the error log• xp_regread
● Useful for programmatically building restore paths, forUseful for programmatically building restore paths, for instance
Inline FunctionsInline Functions
• %%lockres%%● Used to get the lock resource hash value for a row when
investigating incorrect blocking/deadlocking● select * %%lockres%% from t1● select , %%lockres%% from t1
• %%rowdump%%● select *, %%rowdump%% from t1
• %%physloc%%● Used to help find record locations when dealing with corruption● select * %%physloc%%● select , %%physloc%%,
sys.fn_PhysLocFormatter(%%physloc%%) from t1
Demo
Undocumented inline functions
Startup Options (1)Startup Options (1)
• -EE● Lightly documented
(http://support.microsoft.com/kb/329526)● Changes the number of extents allocated by round-
robin allocation during index builds or rebuildsUse for data warehouses with very large index scans● Use for data warehouses with very large index scans
● Increases the size of physical IOs to get better throughputg p
● 2005: 4 extents per file● 2008+: 64 extents per file
Startup Options (2)Startup Options (2)
• -q”collation”q collation● Changes the server collation
• -QQ● 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● This then allows tempdb to be created, as it s created
from model● Must use with T3608 to allow system database
restore
Trace Flags (1)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
661• 661● Disable ghost cleanup task
• 806● Force page audits when pages are read from disk
• 831P t t h d i th b ff l t t h● Protect unchanged pages in the buffer pool to catch memory corruptions
Trace Flags (2)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/920093p pp
• 1117● Force all data files to auto-grow at the same time
• 1118● Disable single-page allocations in tempdb
• See http://support.microsoft.com/kb/328551
• 1211● Disable lock escalation
1224• 1224● Escalate locks only on memory pressure > 40%
Trace Flags (3)Trace Flags (3)
• 1462● Turns off database mirroring compression in 2008+
• 2505● Turns off tracing calls to DBCC TRACEON/TRACEOFF
• 3226● Turns off tracing backup completionsTurns off tracing backup completions
• 3231● Fake NO_LOG/TRUNCATE_ONLY operations
• 3422● Extra auditing of log records
Trace Flags (4)Trace Flags (4)
• 3502● Trace information about checkpoints
• 3604/3605● Allow debug info to be printed to client or errorlog
• 3608● Allows attaching, detaching, and restoring ofsystem databasesAllows attaching, detaching, and restoring ofsystem databases
• 4013● Trace user login information
Demo
Undocumented trace flagsg
ReviewReview
• DBCC commandsDBCC commands• Functions and SPs• Trace flags and startup optionsTrace flags and startup options
• All features I’ve described here are *safe*• All features I ve described here are safe• Make sure you try other undocumented stuff outr
in test before using in productionin test before using in production
• Have fun!• Have fun!
Your Feedback is ImportantYour Feedback is Important
Please fill out a session evaluation formPlease fill out a session evaluation form drop it off at the conference registration
deskdesk.
Th k !Thank you!