What is Happening on Your Server Currently

A great tool to determine what is occurring on your SQL Server right now is the fantastic free stored procedure sp_WhoIsActive.

This procedure can be executed as an alternative to sp_who2 to give far more insightful and useful information.

There are numerous different switches to control behaviour, view all options by executing: –

EXECUTE sp_WhoIsActive @help = 1;

My particular favourite is @get_plans to return the estimated plan from cache of all current connections. This allows you to immediately drill through to the plan if you think you can identify the culprit root cause of your performance issue.

Another great option is to log the results to a table for later analysis. This can be achieved by the following code: –


DECLARE @destination_table VARCHAR(24) = 'dbo.WhoIsActive_'
+ CONVERT(VARCHAR, GETDATE(), 112);
DECLARE @schema NVARCHAR(1000);

EXEC dbo.sp_WhoIsActive @format_output = 0, @return_schema = 1, @get_plans = 1,
@schema = @schema OUTPUT;

SET @schema = REPLACE(@schema, '<table_name>', @destination_table);

IF NOT EXISTS (SELECT * FROM sys.tables WHERE object_id=OBJECT_ID(@destination_table))
BEGIN;
EXECUTE(@schema);
END;

DECLARE @i INT = 0;

WHILE @i < 100
BEGIN;
EXEC dbo.sp_WhoIsActive @format_output = 0, @get_plans = 1,
@destination_table = @destination_table;

SET @i = @i + 1;

WAITFOR DELAY '00:00:05';
END;
GO

Just be aware that table might grow quite large so this is probably not something you want to run continuously.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s