sp_who, sp_who2 & sp_whoisactive

Ever wondered what’s happening inside your SQL Server instance? sp_who, sp_who2 and sp_whoisactive are stored procedures that allow you to view current users, sessions, and processes within a SQL Server instance. This kind of information helps you diagnose blocking issues and monitor general activity.

Among them, sp_whoisactive is a go-to tool for many SQL DBAs & Software Engineers. Created by Adam Machanic, it offers a much richer set of details compared to sp_who and sp_who2. It doesn’t show system processes and provides valuable data, such as running full text of SQL queries and Execution Plans. I would

Let’s take a closer look at these three procedures and how they can help with SQL Server monitoring and troubleshooting.

sp_who

sp_who retrieves information on all active processes in SQL Server at the time of execution. It includes login names, hostnames, current commands being run (not full SQL text), and target databases.

SQL sp_who

The first 50 results are system SPIDS which you’d never try kill. If you’re looking terminating SQL SPIDs, check out my other post: Killing SQL Server Processes.

sp_who2

sp_who2 is an undocumented stored procedure by Microsoft, meaning it could be modified or deprecated without notice. It offers additional columns beyond sp_who, making it slightly more informative.

SQL sp_who2

In my other post I share a simple SQL script that logs sp_who2 results into a temporary table, allowing you to filter and sort sessions in SQL for review. This can be especially useful when investigating blocking issues, long-running queries, or hidden inactive SPIDs that standard scripts might miss. 

sp_whoisactive

Now, this is where things improve. sp_whoisactive provides a comprehensive snapshot of SQL Server’s current activity. Info includes full SQL queries, query plans, hardware usage, temp DB allocations, blocks and more. This 4 minute video by Brent Ozar gives the perfect run-through of it:

To try it yourself, follow these steps:
1. Download sp_whoisactive and execute the script in a query window.
2. Run EXEC sp_whoisactive; to see active sessions.
3. If your test environment is empty, simulate a blocking scenario:
Open a session and start an explicit transaction without committing.
In another session, run a SELECT on the same table—it will get blocked.
Now execute sp_whoisactive to see the blocking details.

SQL Server Blocking SPID

As you can see in the screenshot above, session_id 55 is blocking the SELECT statement from being run. As mentioned above in this post, you might want to kill the lead blocker in SQL if it’s causing a bottleneck.

Most of the time, I run sp_whoisactive without parameters or use @get_plans = 1 to capture execution plans. Depending on the situation, additional parameters can provide more useful info.

A great way to leverage this stored proc is by running it as a SQL Agent job every 30–60 seconds, storing results into a table for historical analysis.

I hope all this was useful for you! Cheers.


Comments

Leave a Reply

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

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Error Messages (5) Failover Cluster Instances (FCI) (1) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Administration (2) Logging & Monitoring (1) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (2) SQL Certificates & Encryption (3) SQL Server Agent (5) SQL Server CDC (2) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (16) SQL Server Networking (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance Tuning (6) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) SQL Server Security (4) SQL Server Storage (10) Windows Admin (21) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)