SQL Server Performance Troubleshooting for Developers

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 googe, 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 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...

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 ,
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
comments powered by Disqus