amachanic / sp_whoisactive

sp_whoisactive
GNU General Public License v3.0
1.14k stars 281 forks source link

Persisting blocked_session_count shows 0 #42

Closed datadill closed 2 years ago

datadill commented 3 years ago

I am trying to persist data into a temp table and it is working properly, except for blocked_session_count. It appears that this value always shows 0 when outputting into a temp table.

I also noticed that when using the @return_schema = 1 parameter it seems to just skip over this column in the table create, which is when I tried to add it manually and noticed it was always 0.

EXEC sp_WhoIsActive @destination_table = '#temp', @Find_Block_leaders = 1, @output_column_list = '[session_id][login_name][blocked_session_count][reads][writes][database_name][program_name][start_time]', @sort_order = '[blocked_session_count] DESC'

So it seems like this is not possible, but please correct me if I am wrong as I would really like to capture this value.

amachanic commented 3 years ago

I tried the following and I do see blocked_session_count in the generated table. Can you confirm?

declare @x varchar(max) = null

exec sp_whoisactive
    @find_block_leaders = 1,
    @return_schema = 1,
    @schema=@x output,
    @output_column_list = '[session_id][login_name][blocked_session_count][reads][writes][database_name][program_name][start_time]'

select @x

I can confirm, however, that blocked_session_count is not working on the output. This is a bug, and I'll try to find time to work on it.

amachanic commented 3 years ago

The issue here is the output column list. Adding [blocking_session_id] to the list will work around the problem - it is filtered too early, and is needed in order to calculate the blocking session count.

erikdarlingdata commented 2 years ago

Closed via #49