How I use sp_WhoIsActive

sp_whoisactive is a nice little tool that has lately been updated by Adam Machanic.

If you work with SQL Server there is no chance you might have missed it. Actually if you don’t know this tool you haven’t play around with SQL Server enough.

Lately, on, I was reading a post and I found one of the question very intriguing: what are your favorite options to use with sp_whoisactive?

My favorite option is…

All the options are very good but my favorite is @destination_table: when used on a job this option allows you to save the output to a table for further investigation.

Let’s create a database and a table

First let’s create a database and a table that will store the data for us:

Let’s create a job to store the data

We now have to fill up that table.

Go to SQL Server Agent > Jobs, and create a job called Feed_WhoIsActive and in the steps put this code:

And set the job to run every minute.

Inserting 1440 rows per day is enough. the table will become quite heavy as it has to store the query plan. It depends by how much your database is under pressure but it might get quite large.

Let’s create a cleanup job

We don’t want to store every single day. Storing the last 10 days in enough.

Let’s create a second job called Clean_WhoIsActive that will delete all data older than 10 days.

And set this to run only once per day.


sp_whoisactive is a powerful tool and it’s very basic.

Install it today and get familiar with it.

There is no PowerBI dashbord out there, I might create one in my spare time. But I still have 9 draft to post on my blog…



Leave a Reply

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