Upload
evelineg
View
221
Download
0
Embed Size (px)
Citation preview
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
1/47
October 11-14, Seattle, WA
Important Trace Flags ThatEvery DBA Should KnowDBA-309
Victor IsakovDatabase Architect / Trainerwww.victorisakov.com
SQL Server Solutionswww.sqlserversolutions.com.au
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
2/47
Abstract
There are a number of important trace flags thatshould be implemented in most productionenvironments, yet many DBAs think that trace flags
should only be used for testing purposes (or to "showoff" at conferences) and that they are not supported.Nothing could be further from the truth! Take traceflag 4199, for example (and yes, it's probably worthyour while reading KB974006 to understand what
trace flag 4199 does!).In this session, Victor will present the important traceflags that all DBAs should know, what they do, whento implement them, and how best to implement themin a production environment.
2DBA-309 | Important Trace Flags That Every DBA Should Know
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
3/47
Speaker
Victor Isakov is a Database Architect and trainerwho provides consulting and training services tovarious organizations in the public, private, andNGO sectors globally.He regularly speaks at international conferences
such as Microsoft TechEd, SQL Connections, PASS
Summit, and SQL Code Camp.He has authored a number of books on SQL Serverand worked with Microsoft to develop the SQLServer exams and certification.In 2007, Victor was invited by Microsoft to attend
the SQL Ranger program in Redmond, WA.Consequently, he was one of the first ITprofessionals to achieve both theMicrosoftCertified Master: SQL ServerandMicrosoftCertified Architect: SQL Servercertificationsglobally. (When it actually meant something! )
3DBA-309 | Important Trace Flags That Every DBA Should Know
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
4/47
Microsoft Certified Master
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
5/47
Speaker
Julie Koesmarno is a Senior SQLServer Developer and aDevelopment DBA.
She is an MCITP and has beenworking with SQL Server for nearly adecade.
She has worked on very large 24/7online systems where over10 millionrecords are processed in a day.
5DBA-309 | Important Trace Flags That Every DBA Should Know
http://localhost/var/www/apps/conversion/tmp/scratch_6//upload.wikimedia.org/wikipedia/commons/9/9b/MCTS_logo.png8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
6/47
Agenda
What is a Trace Flag
Caveats
Implementing Trace Flags PROD Trace Flags
DEV / UAT Trace Flags
DBA-309 | Important Trace Flags That Every DBA Should Know 6
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
7/47
What is a Trace Flag
A trace flag is a directive used to set specificserver characteristics or to switch off a particularbehaviour
Startup Enabled at different scope:
Global Session
Documentation sources:
BOL KB articles / Service Pack & Cumulative Update readmes
White papers Blogs / user groups / water cooler
DBA-309 | Important Trace Flags That Every DBA Should Know 7
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
8/47
Caveat Emptor
Make sure you understand what a trace flag does Recommended to test in DEV / UAT environment first
Microsoft seems to be saying that trace flags are onlysupported if they are documented
Documented: BOL KB articles White papers Service Pack and Cumulative Update readmes
WARNING:These trace flags should be used under the guidanceof Microsoft SQL Server support. They are used in this post fordiscussion purposes only and may not be supported in futureversions.
DBA-309 | Important Trace Flags That Every DBA Should Know 8
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
9/47
Controlling Trace Flags
DBCC TRACEON Use -1 to turn on trace flag globally
DBCC TRACEOFF
DBCC TRACESTATUS
-T startup flag
Sometime trace flags seem to do nothing DBCC TRACEON (3604)
Send output to console
DBCC TRACEON (3605) Send output to ERRORLOG
DBA-309 | Important Trace Flags That Every DBA Should Know 9
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
10/47
Implementing Trace Flags
Microsoft says that you should do it bymodifying the registry
UseT# separated by semi-colon (;) http://msdn.microsoft.com/en-
us/library/ms345416.aspx
SQL Server Configuration Manager
Registry Editor
DBA-309 | Important Trace Flags That Every DBA Should Know 10
http://msdn.microsoft.com/en-us/library/ms345416.aspxhttp://msdn.microsoft.com/en-us/library/ms345416.aspxhttp://msdn.microsoft.com/en-us/library/ms345416.aspxhttp://msdn.microsoft.com/en-us/library/ms345416.aspxhttp://msdn.microsoft.com/en-us/library/ms345416.aspxhttp://msdn.microsoft.com/en-us/library/ms345416.aspx8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
11/47
Implementing Trace Flags:SQL Configuration Manager
DBA-309 | Important Trace Flags That Every DBA Should Know 11
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
12/47
Implementing Trace Flags:REGEDT32
DBA-309 | Important Trace Flags That Every DBA Should Know 12
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
13/47
Implementing Trace Flags:ERRORLOG
DBA-309 | Important Trace Flags That Every DBA Should Know 13
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
14/47
Implementing Trace Flags:Victors Alternative
Create a stored procedure in the MASTERdatabase that enables various trace flags
Mark the above stored procedure as toautostart
sp_procoption [ @ProcName = ] 'procedure' ,
[ @OptionName = ] 'option' ,
[ @OptionValue = ] 'value'
EXEC sp_procoption 'EnableTraceFlags','autostart',
'TRUE'
DBA-309 | Important Trace Flags That Every DBA Should Know 14
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
15/47
Implementing Trace Flags:master.dbo.EnableTraceFlags
DBA-309 | Important Trace Flags That Every DBA Should Know 15
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
16/47
Implementing Trace Flags:ERRORLOG
DBA-309 | Important Trace Flags That Every DBA Should Know 16
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
17/47
Implementing Trace Flags:Startup Trace Flags
Dont forget that not all trace flags can beenabled using DBCC TRACEON
DBA-309 | Important Trace Flags That Every DBA Should Know 17
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
18/47
PROD Trace Flags
The following set of trace flags represent traceflags that you might want to implement in aPROD environment
Change default behavior of the product Improved performance Improved troubleshooting
Generally documented Generally low risk
Might want to consider enabling them on yourstandard build
Please dont sue us if something goes wrong!
DBA-309 | Important Trace Flags That Every DBA Should Know 18
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
19/47
Trace Flag 610
Trace flag 610 controls minimally logged insertsinto indexed tables
Allows for high volume data loading
Less information is written to the transaction log
Transaction log file size can be greatly reduced
Introduced in SQL Server 2008 Very fussy
Documented: Data Loading Performance Guidewhite paper
http://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspx
DBA-309 | Important Trace Flags That Every DBA Should Know 19
http://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspxhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspxhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspxhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspxhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspxhttp://msdn.microsoft.com/en-us/library/dd425070(v=sql.100).aspx8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
20/47
Trace Flag 834
Trace flag 834 allows SQL Server 2005 to use large-pageallocations for the memory that is allocated for the bufferpool.
May prevent the server from starting if memory is fragmented and iflarge pages cannot be allocated
Best suited for servers that are dedicated to SQL Server 2005 Page size varies depending on the hardware platform
Page size varies from 2 MB to 16 MB.
Improves performance by increasing the efficiency of thetranslation look-aside buffer (TLB) in the CPU
Only applies to 64-bit architecture Startup Documented: KB920093
Now automatic: Enterprise / Developer Edition
Lock Pages in Memory privilege
>= 8GB RAM DBA-309 | Important Trace Flags That Every DBA Should Know 20
http://support.microsoft.com/kb/920093http://support.microsoft.com/kb/9200938/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
21/47
Trace Flag 835
Trace flag 835 enables Lock Pages in Memorysupport for SQL Server Standard Edition
Enables SQL Server to use AWE APIs for buffer poolallocation
Avoids potential performance issues due to trimmingworking set
http://msdn.microsoft.com/en-us/library/ms187499.aspx
Introduced in: SQL Server 2005 Service pack 3 Cumulative Update 4
SQL Server 2008 Service Pack 1 Cumulative Update 2 Only applies to 64-bit architecture Startup Documented: KB970070
DBA-309 | Important Trace Flags That Every DBA Should Know 21
http://msdn.microsoft.com/en-us/library/ms187499.aspxhttp://support.microsoft.com/kb/970070http://support.microsoft.com/kb/970070http://msdn.microsoft.com/en-us/library/ms187499.aspxhttp://msdn.microsoft.com/en-us/library/ms187499.aspxhttp://msdn.microsoft.com/en-us/library/ms187499.aspxhttp://msdn.microsoft.com/en-us/library/ms187499.aspx8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
22/47
Trace Flag 835:Example
DBA-309 | Important Trace Flags That Every DBA Should Know 22
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
23/47
Trace Flag 835:Example
DBA-309 | Important Trace Flags That Every DBA Should Know 23
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
24/47
Trace Flag 1118
Trace flag 1118 directs SQL Server to allocate fullextents to each tempdbobjects (instead of mixedextents)
Less contention on internal structures such as SGAM pages Story has improved in subsequent releases of SQL
Server So represents a edge case
Scope: Global
Documented: KB328551, KB936185 Working with tempdb in SQL Server 2005white paper
http://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspx.
DBA-309 | Important Trace Flags That Every DBA Should Know 24
http://support.microsoft.com/kb/328551http://support.microsoft.com/kb/936185http://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspxhttp://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspxhttp://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspxhttp://www.microsoft.com/technet/prodtechnol/sql/2005/workingwithtempdb.mspxhttp://support.microsoft.com/kb/936185http://support.microsoft.com/kb/3285518/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
25/47
Trace Flag 1204
Trace flag 1204 writes information aboutdeadlocks to the ERRORLOG in a text
format
Resources
Types of locks
Command affected
Scope: Global
Documented: BOL
DBA-309 | Important Trace Flags That Every DBA Should Know 25
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
26/47
Trace Flag 1204:
Example
DBA-309 | Important Trace Flags That Every DBA Should Know 26
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
27/47
Trace Flag 1222
Trace flag 1222 writes information aboutdeadlocks to the ERRORLOG in a XML
format
Scope: Global
Documented: BOL
DBA-309 | Important Trace Flags That Every DBA Should Know 27
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
28/47
Trace Flag 1222:
Example
DBA-309 | Important Trace Flags That Every DBA Should Know 28
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
29/47
Trace Flag 1211
Trace flag 1211 disables lock escalation based onmemory pressure or number of locks
Database engine will not escalate row or page locks to tablelocks
Scope: Global | Session Documented: BOL
Trace flag 1211 takes precedence over 1224
Microsoft recommends using 1224 Trace flag 1211 prevents escalation in every case, even under
memory pressure Helps avoid "out-of-locks" errors when many locks are being used.
Can generate excessive number of locks Can slow performance
Cause 1204 errors
DBA-309 | Important Trace Flags That Every DBA Should Know 29
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
30/47
Trace Flag 1224
Trace flag 1224 disables lock escalation basedon the number of locks
Memory pressure can still trigger lock
escalation Database engine will escalate row or page
locks to table locks 40% of memory available for locking
sp_configure locks Non-AWE memory
Scope: Global | Session
Documented: BOL
DBA-309 | Important Trace Flags That Every DBA Should Know 30
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
31/47
Trace Flag 2528
Trace flag 2528 disables parallel checking ofobjects during DBCC CHECKDB, DBCCCHECKFILEGROUP and DBCC CHECKTABLE.
Scope: Global | Local Documented: BOL
Typically leave parallel DBCC checks enabled DBCC operations can dynamically change their
degree of parallelism Alternatives:
MAXDOP option
Resource Governor
DBA-309 | Important Trace Flags That Every DBA Should Know 31
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
32/47
Trace Flag 3226
Trace flag 3226 prevents successful backoperations from being logged
By default SQL Server logs every successfulbackup operation to the ERRORLOG andthe System event log
Frequent backup operations can cause log
files to grow and make finding othermessages harder
Documented: BOL
DBA-309 | Important Trace Flags That Every DBA Should Know 32
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
33/47
Trace Flag 4199 /* IMPORTANT */
Trace flag 4199 enables all the fixes that were previouslymade for the query processor under many trace flags
Policy: Any hotfix that could potentially affect the execution plan of
a query must be controlled by a trace flag Except for fixes to bugs that can cause incorrect results or corruption
Helps avoid unexpected changes to the execution plan
Which means that virtually everyone is not necessarilyrunning SQL Server with all the latest query processorfixes enabled
Scope: Session | Global Documented: KB974006 Consider enabling for virgin SQL Server deployments?
Microsoft are strongly advising not to enable this traceflag unless you are affected
DBA-309 | Important Trace Flags That Every DBA Should Know 33
http://support.microsoft.com/kb/974006http://support.microsoft.com/kb/9740068/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
34/47
DEV / UAT Trace Flags
The following set of trace flags representtrace flags that you might want toimplement in a DEV / UAT environment
Might impact your PROD environment Adversely!
Help develop / troubleshoot / learn
Or to troubleshoot / verify something in
PROD environment Generally low risker but not something your would want to
have permanently enabled
Generally not documented
DBA-309 | Important Trace Flags That Every DBA Should Know 34
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
35/47
Trace Flag 806
Trace Flag 806 enables DBCC audit checks tobe performed on pages to test for logicalconsistency problems.
These checks try to detect when a read operation from a disk
does not experience any errors but the read operation returnsdata that is not valid.
Pages will be audited every time that they are read from disk
Page auditing can affect performance andshould only be used in systems where data
stability is in question. Documented: KB841776
SQL Server I/O Basics, Chapter 2 white paper http://technet.microsoft.com/en-au/library/cc917726.aspx
DBA-309 | Important Trace Flags That Every DBA Should Know 35
http://support.microsoft.com/kb/841776http://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://support.microsoft.com/kb/8417768/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
36/47
Trace Flag 818
Trace flag 818 enables an in-memory ringbuffer that is used for tracking the last 2,048successful write operations that are performed
by the computer running SQL Server, notincluding sort and workfile I/Os
Use to further diagnose operating system,driver, or hardware problems causing lost writeconditions or stale read conditions
May see data integrity-related error messagessuch as errors 605, 823, 3448.
Documented: KB826433
DBA-309 | Important Trace Flags That Every DBA Should Know 36
http://support.microsoft.com/kb/826433http://support.microsoft.com/kb/8264338/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
37/47
Trace Flag 3422
Trace Flag 3422 enables log record auditing
Troubleshooting a system that is experiencingproblems with log file corruption may be easier
using the additional log record audits this traceflag provides
Use this trace flag with caution as it introducesoverhead to each transaction log record
Similarly to trace flag 806, you would only use
this to troubleshoot corruption problems Documented:
SQL Server I/O Basics, Chapter 2 white paper http://technet.microsoft.com/en-au/library/cc917726.aspx
DBA-309 | Important Trace Flags That Every DBA Should Know 37
http://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspx8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
38/47
Trace Flag 1200
Trace flag 1200 returns locking informationin real-time as your query executes
Use during development / testing phase Great for learning how SQL Server
implements locking
DBA-309 | Important Trace Flags That Every DBA Should Know 38
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
39/47
Trace Flag 1806
Trace flag 1806 explicitly disables instant fileinitialization
SQL Server will zero initialize files
Obviously not same as DOD-compliant secure clearing /sanitizing standard (and other country standards)
Used to guarantee the physical data file spaceacquisition during data file creation or expansion,on a thin provisioned subsystem
Documented: SQL Server I/O Basics, Chapter 2white paper
http://technet.microsoft.com/en-au/library/cc917726.aspx
DBA-309 | Important Trace Flags That Every DBA Should Know 39
http://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspxhttp://technet.microsoft.com/en-au/library/cc917726.aspx8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
40/47
Trace Flag 3004
Trace Flag 3004 returns more informationabout instant file initialization
Can be used to ensure that SQL Server hasbeen configured to take advantage of IFIcorrectly
DBA-309 | Important Trace Flags That Every DBA Should Know 40
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
41/47
Trace Flag 3014
Trace Flag 3014 returns more information tothe ERRORLOG about BACKUP
Backup activity
Restore activity
File creation
DBA-309 | Important Trace Flags That Every DBA Should Know 41
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
42/47
Trace Flag 3502
Trace Flag 3502 writes information aboutCHECKPOINTs to the ERRORLOG
DBA-309 | Important Trace Flags That Every DBA Should Know 42
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
43/47
Traceflag 3505
Setting trace flag 3505 disables automaticcheckpoints.
Setting trace flag 3505 may increase recovery timeand can prevent log space reuse until the next
checkpoint is issued. Make sure to issue manual checkpoints on all
read/write databases at appropriate time intervals
For high availability systems, such as clusters,Microsoft recommends that you do not
change the recovery interval because it mayaffect data safety and availability.
Documented: KB815436
DBA-309 | Important Trace Flags That Every DBA Should Know 43
http://support.microsoft.com/kb/815436http://support.microsoft.com/kb/8154368/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
44/47
Summary
Make sure you understand and / or test traceflags before deploying them in PRODenvironments
Decide upon a standard set of trace flags thatyou will enable as part of your standard build
Decide upon a standard way of deploying traceflags
Make sure you read up on trace flag 4199
There are a lot more trace flags out there What I am planning to do in October 2011 is to
blog about a different trace flag every day www.victorisakov.com
DBA-309 | Important Trace Flags That Every DBA Should Know 44
http://www.victorisakov.com/http://www.victorisakov.com/8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
45/47
Q & A
Questions?
DBA-309 | Important Trace Flags That Every DBA Should Know 45
Email [email protected]
Blog www.victorisakov.com
Twitter @victorisakov
LinkedIn www.linkedin.com/in/victorisakov
Website www.sqlserversolutions.com.au
Certification
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
46/47
Complete the Evaluation Form
to Win!Win a Dell Mini Netbookevery dayjust for handingin your completed form. Each session evaluation formrepresents a chance to win.
Pick up your evaluation form: In each presentation room
Online on the PASS Summit website
Drop off your completed form: Near the exit of each presentation room
At the Registration desk
Online on the PASS Summit website
Sponsored by Dell
46DBA-309 | Important Trace Flags That Every DBA Should Know
8/10/2019 SQL Pass Summit 2011-Important Trace Flags That Every DBA Should Know-Victor Isakov
47/47
Thank youfor attending this session and the2011 PASS Summit in Seattle