Sql server troubleshooting
-
Upload
nathan-winters -
Category
Technology
-
view
129 -
download
1
description
Transcript of Sql server troubleshooting
SQL Server Troubleshooting and Performance Monitoring
And throw in some performance tuning for giggles
IntroStacy HeinDatabase Guy
Start with the Basics
Start with the tools you knowLogs, Logs, LogsPerformance Monitor
Some tools you might not knowTracesProfiler TracesExecution plansToad or other third party applications
Why do performance monitoring?Goes hand-in-hand with troubleshootingIdentify bottlenecks (CPU, Memory, SQL queries, etc.)Planning (capacity management, end-of-life, etc.)Identify server/instance configuration issuesBase-lining your servers
Should start troubleshooting the SQL Server before the client says there is an issue.
The Usual SuspectsMemoryProcessorDiskDatabase instance configurationQueriesMaintenance
Performance CountersRemember that performance counters should not be
taken individually. Get the whole story.Most thresholds are dependent on the system and
application.Ignore spikes. Sustained thresholds are the only ones
that count.
MemoryA good place to start generally.
64 bit has helped with both memory and processor bottlenecks.
More is good – always.
Memory Performance CountersMemory: Available Bytes
Key counter especially when used with others.Memory: Pages / sec
Hard page faults – going to disk to get it.VMM goes to pagefile to retrieve.Above 20 suggests possible memory issue.
Memory: Page Faults / Sec Sum of hard an soft page faults
Memory Performance CountersPage File: % Usage
Also useful with the other counters.
Some rules for the pagefileMove from system diskPut on more than one drive if possibleMake it 2 times the size of the physical RAM in the server
Processor Performance CountersProcessor:% Processor Time
Total processing time for non-idle thread80-90% means need processor
Processor: %User TimeTotal time used for executing user processes (e.g. SQL)
System: Processor QueueOver 2 = badConsider how many cores and divide total by number of
cores
Disk Performance CountersPhysical disk
PhysicalDisk: Avg. Read Queue Length Should be less than 2
PhysicalDisk: Avg. Write Queue Length Should be less than 2
PhysicalDisk: % Disk Time more than 50% indicates a bottleneck
Disk Performance CountersLogical Disk
SQL Server:Buffer Manager:Page reads/sec SQL Server reading pages from disk. If you are near your
hardware maximums for this counter tune your database by adding indexes, redesign queries, etc.
SQL Server:Buffer Manager:Page writes/sec SQL Server writing pages to disk. If you are near your hardware
maximums for this counter tune your database by adding indexes, redesign queries, etc.
Networking Performance CountersNetwork Interface\ Bytes Total/sec Network Interface\ Bytes Sent/sec Network Interface\ Bytes Received/sec Network Interface\ Current Bandwidth5
Don’t usually have a networking issue that is not the cable, the NIC, or route/rule issues.
Dynamic Management Views and FunctionsCan get performance counter data from these. Is a snapshot not continuousCommon ones used
sys.dm_os_performance_counters sys.dm_os_sys_info sys.dm_os_wait_stats sys.dm_io_virtual_file_stats - function
Trace FlagsUsed in determining deadlocks (in this case anyway)1204
Reports deadlock information formatted by each node involved in the deadlock
1222formats deadlock information, first by processes and then
by resourcesUse DBCC TRACEON to set
Profiler is your FriendCan execute and capture trace information for all
transactions running on SQL server instance.Can isolate transactions you need to capture.
Database Instance ConfigurationCan affect server performanceExamples
Memory settings, processor affinity settings, affinity masks, AWE setting (for 32 bit instances), etc.
If you are going to change your settings, understand the instances role
Instance RolesHigh Write Instance
The database and log disk should be RAID 10 and separated on different physical volumes.
The logical and physical model of the database is important. High write tables should be on their own partitions. This is also be true for very large, clustered indexes.
Tempdb should be on its own RAID 10 partition and should have one data file for each core dedicated to SQL Server.
Although disk is usually the primary issue with a high write system, put as much RAM as you can in this system.
Instance RolesHigh Read Instance (Reporting?)
Memory, Memory, Memory is the most important component to a read-intensive system. The more you have the more that can be accessed in memory and not read from disk.
Tempdb should be on its own RAID 10 partition and should have one data file for each core dedicated to SQL Server. If you are doing massive reads, you are probably doing calculations for reporting. This operations are handled in tempdb now in SQL Server 2005 and forward.
Although memory is the key to a system that does massive read operations, if you can afford it, make the database and log file partitions RAID 10 for when you would need to access them.
Instance RolesIf your system is a hybrid the defaults should work for the
server. If not, tweak design and system settings as necessary careful to consider what the instance might be processing (i.e. more reads or more writes).
Other Keys to Troubleshooting
Understand the data and applications on the instanceThe physical and logical design of the database coupled
with the system setting will go far in establishing a high performing instance/server.
Well designed queries are also
Tuning QueriesExecution PlansProfilerThird party apps
Toad for SQL Server
Tuning QueriesRules for code creation
Use procedures for the repetitive queriesAvoid cursorsReduces the use of temp tables Return only the rows an app needsSet NOCOUNT ONUse the schema when naming the objectDo all DDL at top of proceduresUse ANSI JOIN languageLook for ANSI SET commands in your code
MaintenanceDatabase maintenance is key to mitigating some performance
problems. Backups for obvious reasonsIndex fragmentation can cause issues for the server.
Two options DBCC DBREINDEX and DBCC INDEXDEFRAGUPDATE STATISTICS - depends on your application.
Be careful there is a performance trade off for recompiling queries.
Maintenance is a key component to the preventative side of
server support.