How to get blocked objects?

  • Hello all,

    I was dealing with some blocked sessions and I wonder if there is a way to know exactly what object is being blocked, I know how to get what spid is blocking the others, but I think it will be really usefull to know the table...

    Thanks in advance

  • ricardo_chicas (10/5/2010)


    Hello all,

    I was dealing with some blocked sessions and I wonder if there is a way to know exactly what object is being blocked, I know how to get what spid is blocking the others, but I think it will be really usefull to know the table...

    Thanks in advance

    Use sp_lock, the spid(s), and objID


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Thank you

    but.. what happen when I get this after running sp_lock:

    spid__dbid__ObjId__indId__type__resource__mode__status

    545___6_____0_____0_____DB_____________S____GRANT

    There isn't an objectid....

  • Use the following query:

    see the output query and the tables in the query.

    select req.session_id, ses.login_name,req.blocking_session_id,sqltext.TEXT, req.session_id, req.status, req.command, req.cpu_time, req.total_elapsed_time

    from sys.dm_exec_requests req left join sys.dm_exec_sessions ses on req.session_id= ses.session_id

    cross apply sys.dm_exec_sql_text(sql_handle) as sqltext

    [font="Tahoma"]
    --SQLFRNDZ[/url]
    [/font]

  • Although, using sys.dm_exec_requests won't show blocking if parallelism is involved.

    Another way to do it, and you can use almost the same query, is to look at sys.dm_os_waiting_tasks.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thank you guys,

    Now I have what I needed 🙂

  • select session_id,wait_duration_ms,

    wait_type,blocking_session_id

    from sys.dm_os_waiting_tasks where session_id >50 and blocking_session_id is not null

    Run this and the before query I posted for daily thats it you are done.

    [font="Tahoma"]
    --SQLFRNDZ[/url]
    [/font]

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply