sql server troubleshooting

24
SQL Server Troubleshooting and Performance Monitoring And throw in some performance tuning for giggles

Upload: nathan-winters

Post on 27-Jan-2015

139 views

Category:

Technology


1 download

DESCRIPTION

Stacy Hein

TRANSCRIPT

Page 1: Sql server troubleshooting

SQL Server Troubleshooting and Performance Monitoring

And throw in some performance tuning for giggles

Page 2: Sql server troubleshooting

IntroStacy HeinDatabase Guy

Page 3: Sql server troubleshooting

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

Page 4: Sql server troubleshooting

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.

Page 5: Sql server troubleshooting

The Usual SuspectsMemoryProcessorDiskDatabase instance configurationQueriesMaintenance

Page 6: Sql server troubleshooting

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.

Page 7: Sql server troubleshooting

MemoryA good place to start generally.

64 bit has helped with both memory and processor bottlenecks.

More is good – always.

Page 8: Sql server troubleshooting

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

Page 9: Sql server troubleshooting

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

Page 10: Sql server troubleshooting

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

Page 11: Sql server troubleshooting

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

Page 12: Sql server troubleshooting

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.

Page 13: Sql server troubleshooting

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.

Page 14: Sql server troubleshooting

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

Page 15: Sql server troubleshooting

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

Page 16: Sql server troubleshooting

Profiler is your FriendCan execute and capture trace information for all

transactions running on SQL server instance.Can isolate transactions you need to capture.

Page 17: Sql server troubleshooting

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

Page 18: Sql server troubleshooting

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.

Page 19: Sql server troubleshooting

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.

Page 20: Sql server troubleshooting

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).

Page 21: Sql server troubleshooting

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

Page 22: Sql server troubleshooting

Tuning QueriesExecution PlansProfilerThird party apps

Toad for SQL Server

Page 23: Sql server troubleshooting

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

Page 24: Sql server troubleshooting

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.