Sql server troubleshooting


Published on

Stacy Hein

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Sql server troubleshooting

  1. 1. SQL Server Troubleshooting and Performance Monitoring<br />And throw in some performance tuning for giggles<br />
  2. 2. Intro <br />Stacy Hein<br />Database Guy<br />
  3. 3. Start with the Basics<br />Start with the tools you know<br />Logs, Logs, Logs<br />Performance Monitor<br />Some tools you might not know<br />Traces<br />Profiler Traces<br />Execution plans<br />Toad or other third party applications<br />
  4. 4. Why do performance monitoring? <br />Goes hand-in-hand with troubleshooting<br />Identify bottlenecks (CPU, Memory, SQL queries, etc.)<br />Planning (capacity management, end-of-life, etc.)<br />Identify server/instance configuration issues<br />Base-lining your servers<br />Should start troubleshooting the SQL Server before the client says there is an issue.<br />
  5. 5. The Usual Suspects<br />Memory<br />Processor<br />Disk<br />Database instance configuration<br />Queries<br />Maintenance<br />
  6. 6. Performance Counters<br />Remember that performance counters should not be taken individually. Get the whole story.<br />Most thresholds are dependent on the system and application.<br />Ignore spikes. Sustained thresholds are the only ones that count.<br />
  7. 7. Memory <br />A good place to start generally.<br />64 bit has helped with both memory and processor bottlenecks.<br />More is good – always.<br />
  8. 8. Memory Performance Counters<br />Memory: Available Bytes<br />Key counter especially when used with others.<br />Memory: Pages / sec <br />Hard page faults – going to disk to get it.<br />VMM goes to pagefile to retrieve.<br />Above 20 suggests possible memory issue.<br />Memory: Page Faults / Sec <br />Sum of hard an soft page faults<br />
  9. 9. Memory Performance Counters<br />Page File: % Usage <br />Also useful with the other counters.<br />Some rules for the pagefile<br />Move from system disk<br />Put on more than one drive if possible<br />Make it 2 times the size of the physical RAM in the server<br />
  10. 10. Processor Performance Counters<br />Processor:% Processor Time<br />Total processing time for non-idle thread<br />80-90% means need processor<br />Processor: %User Time<br />Total time used for executing user processes (e.g. SQL)<br />System: Processor Queue<br />Over 2 = bad<br />Consider how many cores and divide total by number of cores <br />
  11. 11. Disk Performance Counters<br />Physical disk<br />PhysicalDisk: Avg. Read Queue Length  Should be less than  2 <br />PhysicalDisk: Avg. Write Queue Length  Should be less than 2 <br />PhysicalDisk: % Disk Time  more than 50% indicates a bottleneck <br />
  12. 12. Disk Performance Counters<br />Logical Disk<br />SQL Server:BufferManager:Page reads/sec <br />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.<br />SQL Server:BufferManager:Page writes/sec <br />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.<br />
  13. 13. Networking Performance Counters<br />Network Interface Bytes Total/sec <br />Network Interface Bytes Sent/sec <br />Network Interface Bytes Received/sec <br />Network Interface Current Bandwidth5<br />Don’t usually have a networking issue that is not the cable, the NIC, or route/rule issues.<br />
  14. 14. Dynamic Management Views and Functions<br />Can get performance counter data from these. <br />Is a snapshot not continuous<br />Common ones used<br />sys.dm_os_performance_counters<br />sys.dm_os_sys_info<br />sys.dm_os_wait_stats<br />sys.dm_io_virtual_file_stats - function<br />
  15. 15. Trace Flags<br />Used in determining deadlocks (in this case anyway)<br />1204<br />Reports deadlock information formatted by each node involved in the deadlock<br />1222<br />formats deadlock information, first by processes and then by resources<br />Use DBCC TRACEON to set<br />
  16. 16. Profiler is your Friend<br />Can execute and capture trace information for all transactions running on SQL server instance.<br />Can isolate transactions you need to capture.<br />
  17. 17. Database Instance Configuration<br />Can affect server performance<br />Examples<br />Memory settings, processor affinity settings, affinity masks, AWE setting (for 32 bit instances), etc.<br />If you are going to change your settings, understand the instances role<br />
  18. 18. Instance Roles<br />High Write Instance<br />The database and log disk should be RAID 10 and separated on different physical volumes.<br />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.<br />Tempdb should be on its own RAID 10 partition and should have one data file for each core dedicated to SQL Server.<br />Although disk is usually the primary issue with a high write system, put as much RAM as you can in this system.<br />
  19. 19. Instance Roles<br />High Read Instance (Reporting?)<br />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.<br />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.<br />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.<br />
  20. 20. Instance Roles<br />If 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).<br />
  21. 21. Other Keys to Troubleshooting <br />Understand the data and applications on the instance<br />The physical and logical design of the database coupled with the system setting will go far in establishing a high performing instance/server. <br />Well designed queries are also <br />
  22. 22. Tuning Queries<br />Execution Plans<br />Profiler<br />Third party apps<br />Toad for SQL Server<br />
  23. 23. Tuning Queries<br />Rules for code creation<br />Use procedures for the repetitive queries<br />Avoid cursors<br />Reduces the use of temp tables <br />Return only the rows an app needs<br />Set NOCOUNT ON<br />Use the schema when naming the object<br />Do all DDL at top of procedures<br />Use ANSI JOIN language<br />Look for ANSI SET commands in your code<br />
  24. 24. Maintenance<br />Database maintenance is key to mitigating some performance problems. <br />Backups for obvious reasons<br />Index fragmentation can cause issues for the server.<br />Two options DBCC DBREINDEX and DBCC INDEXDEFRAG<br />UPDATE STATISTICS - depends on your application.<br />Be careful there is a performance trade off for recompiling queries.<br /> <br />Maintenance is a key component to the preventative side of server support.<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.