DBCC - Dubi Lebel
-
Upload
sqlservercoil -
Category
Technology
-
view
1.412 -
download
5
description
Transcript of DBCC - Dubi Lebel
DBCC documented and undocumented,
useful or un-usefulDubi Lebel
D.B.A. = Don’t bother Asking
Dubi Or Not To Be
Introduction
Nice to meet you…..
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!
Undocumented DBCC Commands
http://sqlgeek.pl/Download/Scripts/20091230_DBCC_Script.txt
DBCC HELP('help')
---------------------------------------------
dbcc help
(
{ 'dbcc_statement' | @dbcc_statement_var | '?' }
)
[ WITH NO_INFOMSGS ]
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC HELPDBCC HELP('?')---------------------------
Checkalloc checkcatalog
Checkconstraints checkdb
Checkfilegroup checkident
Checktable cleantable
Dbreindex dropcleanbuffers
Free freeproccache
Freesessioncache freesystemcache
Help indexdefrag
Inputbuffer opentran
Outputbuffer pintable
Proccache show_statistics
Showcontig shrinkdatabase
Shrinkfile sqlperf
Traceoff traceon
Tracestatus unpintable
Updateusage useroptions
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
DBCC HELP('CHECKTABLE')DBCC HELP('CHECKTABLE') ------------------------
dbcc CHECKTABLE
(
{ 'table_name' | 'view_name' }
[ , NOINDEX
| index_id
| { REPAIR_ALLOW_DATA_LOSS
| REPAIR_FAST
| REPAIR_REBUILD
} ]
)
[ WITH
{
[ ALL_ERRORMSGS ]
[ , [ NO_INFOMSGS ] ]
[ , [ TABLOCK ] ]
[ , [ ESTIMATEONLY ] ]
[ , [ PHYSICAL_ONLY ] ]
[ , [ EXTENDED_LOGICAL_CHECKS ] ]
}
]
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
ms-help://MS.SQLCC.v10/MS.SQLSVR.v10.en/s10de_6tsql/html/0d6cb620-eb58-4745-8587-4133a1b16994.htm
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
Trace Flags vs. DBCCTrace 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
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
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
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
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
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.
TF Using RegEdit • Regedit•
TF Using startup parameters
Check the Errorlog
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'
Note
•Trace flag behavior may not be supported in future releases of SQL Server
• BOL & http://msdn.microsoft.com/en-us/library/ms188396.aspx
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
MHTML Document
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.
TF _DEMO 01TF 652
Click icon to add picture
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.
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
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.
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
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
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/archive/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
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.
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.
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
TF _DEMO 02TF 1117
Click icon to add picture
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.
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.
TF _DEMO 03TF 1204, 1205, 1222
Click icon to add picture
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 ,
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.
3014: More information on Backup
• undocumented • returns more information to the ERRORLOG about
BACKUP.
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.
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
TF _DEMO 04Backup/Restore TF
Click icon to add picture
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.
3502: Prints a message to the log at the start and end of each checkpoint.
TF _DEMO 05TF 3502
Click icon to add picture
More, I/o subsystem:• SQL Server 2000 I/O Basics (2005) http://
technet.microsoft.com/en-au/library/cc966500.aspx • SQL Server I/O Basics, Chapter 2 http://
technet.microsoft.com/en-au/library/cc917726.aspx
more• Trace flag 2528 disables parallel checking of objects during
DBCC CHECKDB, DBCC CHECKFILEGROUP and DBCC CHECKTABL
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.