What callstack can tell you in Microsoft SQL Server

In previous article Slow TRUNCATE: Diagnosing SQL Server Spinlock Contention – SQL Peak Performance call stack analysis was one of key point to troubleshoot the issue. But what exactly is a call stack, where we can get it and what tools to use?

Call Stack in ms SQL Server

When a function in a program is called, its address (which is like a specific location or marker in the program) gets added to call stack list. This list keeps track of all the functions that are being called, one on top of another. The function that’s currently running is at the top of this list. When this function calls another function, the new one goes on top, and the original one moves down. This list, with all the functions and their addresses, is known as the call stack. It shows the order of function calls. As the program runs, functions call other functions, creating a trail of activity. By looking at the call stack, you can see this trail and get clues about what the program is doing at any moment.

Where to Find Call Stacks in SQL Server

In SQL Server, call stacks can be encountered in several places, each providing different insights into the internal workings and processes of the SQL Server instance. Here are a few key locations where you might come across call stacks:

  1. Error Logs: SQL Server error logs can contain call stacks, especially when the server encounters a critical error that leads to a crash or other issues.
  2. Extended Events (XE): Extended events sessions can be configured to capture call stack information for specific events. This feature is particularly useful for detailed performance analysis and troubleshooting.
  3. Dump Files: When SQL Server crashes or is manually triggered to produce a dump (DBCC STACKDUMP/DBCC DUMPTRIGGER etc), the resulting dump files contain the call stack at the time of the crash or trigger. Analyzing these files requires specialized tools like WinDbg and symbols to translate memory addresses into readable function calls.

SQLCallStackResolver: A Tool for Insight

Working as a SQL Server support engineer at Microsoft, I had the opportunity to use an invaluable tool that has become publicly available: SQLCallStackResolver. Hosted on GitHub (SQLCallStackResolver), this tool is a game-changer for anyone looking to decode SQL Server call stacks. It aids in resolving the addresses seen in a call stack to their corresponding function names, making the process of diagnosing and understanding performance issues, crashes, or any abnormal behavior in SQL Server significantly more manageable.

Understanding call stacks in SQL Server can significantly enhance your ability to diagnose and resolve complex issues, optimize performance, and gain deeper insights into the inner workings of SQL Server instances.

Please feel free to ask questions in comments.

Mihail Petuhov

Author: Mihail Petuhov

Since 2011, making SQL Server faster.

Leave a Reply