Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

SQL Server Performance Troubleshooting for Developers

0.00/5 (No votes)
23 Jan 2014CPOL1 min read 7.7K  
Some tips for developers who have to deal with a slow SQL server.

Introduction

Suppose you have SQL server with performance issues, (web) apps become slow, there are timeouts, something has to be done.

  • If it's only your app accessing the SQL server, go ahead, use whatever profiler you like, fix SELECT N+1, optimize queries, etc.
  • If you have a (competent) DBA, let him or her handle it

But, what if your boss comes in and says "We have issues with a database server, you have to fix it. Oh, and by the way, we don't have access to the apps using it.

Of course Google will help you, sometime.

Here is what might be the result of some Google, trial and error:

  • Setup monitoring, e.g., New Relic's Server Monitoring and their SQL server plugin
  • Check same basics about the server (Power options, AV exclusions for db files, error in the EventLog or SQL server logs, etc.)
  • Ask Brent, the guy who helps running Stackoverflow on SQL server
    • Literally, Ask Brent
    • Read and watch whatever you can find on his site, it's pure gold!
  • Use sp_Blitz to get a quick overview of (potential) issues together with links offering background knowledge and tips on how to fix them
  • Find the most expensive missing indexes (see script below, I can't remember were I found it)
  • Run sp_BlitzIndex for single databases, start with the ones containing the most expensive missing indexes

If all of this doesn't help, it may be time to really ask for help...

SQL
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT TOP 25 ROUND(s.avg_total_user_cost * s.avg_user_impact * _
(s.user_seeks + s.user_scans),0) AS [Total Cost] ,
              d.[statement] AS [Table Name] ,
              equality_columns ,
              inequality_columns ,
              included_columns
FROM sys.dm_db_missing_index_groups g
INNER JOIN sys.dm_db_missing_index_group_stats s ON s.group_handle = g.index_group_handle
INNER JOIN sys.dm_db_missing_index_details d ON d.index_handle = g.index_handle
ORDER BY [Total Cost] DESC

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)