Script: Check Worker Threads and Active Sessions

This script shows the current SQL Server worker thread count along with all active sessions and requests. It provides a live view of CPU usage, blocking, waits, running commands, and transaction activity.

This is a practical script for performance troubleshooting when an instance appears busy, unresponsive, or under pressure.


The Script


Example Output

The first result set shows the total number of worker threads currently in use by SQL Server.

The second result set lists active sessions and requests, including blocking relationships, wait types, CPU time, reads, writes, and the currently executing statement.

This provides a live view of what the instance is doing at that moment.

SQL Server query showing worker threads and active session details

Notes

  • Worker threads are the execution threads SQL Server uses to process requests
  • High worker thread counts are normal on busy systems, but sudden spikes combined with long waits or blocking can indicate pressure
  • Blocking session IDs help quickly identify blocking chains
  • Useful during real-time performance incidents

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *