Blocking on tempdb system tables

  • Hi, we are having blocking issues with tempdb database, blocking transaction is open for 30 minutes and has create table #Table statements in it, because of this tempdb system catalogs: sys.partitions and sys.allocation_units are locked until the transaction is committed. (Is this the intended behavior, locks on system views?)

    The blocked query is:

    select @reservedpages = sum(a.total_pages),

    @usedpages = sum(a.used_pages),

    @pages = sum(

    CASE

    -- XML-Index and FT-Index-Docid is not considered "data", but is part of "index_size"

    When it.internal_type IN (202,204) Then 0

    When a.type <> 1 Then a.used_pages

    When p.index_id < 2 Then a.data_pages

    Else 0

    END

    )

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    which is I guess part of sp_spaceused system sp, this is called by SCOM db size monitor, as sys.partitions and sys.allocation_units are locked, this query waits for 30 minutes and causing a blocking alert at SCOM monitor.

    How can I resolve this blocking? Is there a way to make the system tables free of lock? Especially for tempdb, Does every open transaction creates #table causes the tempdb system tables locked?

    Any answers appreciated,

  • sporoy (9/12/2010)


    Hi, we are having blocking issues with tempdb database, blocking transaction is open for 30 minutes and has create table #Table statements in it, because of this tempdb system catalogs: sys.partitions and sys.allocation_units are locked until the transaction is committed. (Is this the intended behavior, locks on system views?)

    The blocked query is:

    select @reservedpages = sum(a.total_pages),

    @usedpages = sum(a.used_pages),

    @pages = sum(

    CASE

    -- XML-Index and FT-Index-Docid is not considered "data", but is part of "index_size"

    When it.internal_type IN (202,204) Then 0

    When a.type <> 1 Then a.used_pages

    When p.index_id < 2 Then a.data_pages

    Else 0

    END

    )

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    which is I guess part of sp_spaceused system sp, this is called by SCOM db size monitor, as sys.partitions and sys.allocation_units are locked, this query waits for 30 minutes and causing a blocking alert at SCOM monitor.

    How can I resolve this blocking? Is there a way to make the system tables free of lock? Especially for tempdb, Does every open transaction creates #table causes the tempdb system tables locked?

    Any answers appreciated,

    Whenever possible use table variables a.k.a. @Tables rather than temporary tables a.k.a. #Tables.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • PaulB-TheOneAndOnly (9/12/2010)


    sporoy (9/12/2010)


    Hi, we are having blocking issues with tempdb database, blocking transaction is open for 30 minutes and has create table #Table statements in it, because of this tempdb system catalogs: sys.partitions and sys.allocation_units are locked until the transaction is committed. (Is this the intended behavior, locks on system views?)

    The blocked query is:

    select @reservedpages = sum(a.total_pages),

    @usedpages = sum(a.used_pages),

    @pages = sum(

    CASE

    -- XML-Index and FT-Index-Docid is not considered "data", but is part of "index_size"

    When it.internal_type IN (202,204) Then 0

    When a.type <> 1 Then a.used_pages

    When p.index_id < 2 Then a.data_pages

    Else 0

    END

    )

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    which is I guess part of sp_spaceused system sp, this is called by SCOM db size monitor, as sys.partitions and sys.allocation_units are locked, this query waits for 30 minutes and causing a blocking alert at SCOM monitor.

    How can I resolve this blocking? Is there a way to make the system tables free of lock? Especially for tempdb, Does every open transaction creates #table causes the tempdb system tables locked?

    Any answers appreciated,

    Whenever possible use table variables a.k.a. @Tables rather than temporary tables a.k.a. #Tables.

    Owch! Sorry... That's just some plain ol' bad advice, Paul. Table Variables can be a huge performance problem if any size to them occurs especially since the optimizer sees them as a single row. I'll agree that "It Depends" but making a blanket statement to use table variables whenever possible is just flat out wrong. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • sporoy (9/12/2010)


    Hi, we are having blocking issues with tempdb database, blocking transaction is open for 30 minutes and has create table #Table statements in it, because of this tempdb system catalogs: sys.partitions and sys.allocation_units are locked until the transaction is committed. (Is this the intended behavior, locks on system views?)

    The blocked query is:

    select @reservedpages = sum(a.total_pages),

    @usedpages = sum(a.used_pages),

    @pages = sum(

    CASE

    -- XML-Index and FT-Index-Docid is not considered "data", but is part of "index_size"

    When it.internal_type IN (202,204) Then 0

    When a.type <> 1 Then a.used_pages

    When p.index_id < 2 Then a.data_pages

    Else 0

    END

    )

    from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id

    left join sys.internal_tables it on p.object_id = it.object_id

    which is I guess part of sp_spaceused system sp, this is called by SCOM db size monitor, as sys.partitions and sys.allocation_units are locked, this query waits for 30 minutes and causing a blocking alert at SCOM monitor.

    How can I resolve this blocking? Is there a way to make the system tables free of lock? Especially for tempdb, Does every open transaction creates #table causes the tempdb system tables locked?

    Any answers appreciated,

    I see the blocked query... what does the entire blocking query look like? Also, you mention "transactions"... are you populating a temp table within an explicit transaction???

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (9/12/2010)


    Owch! Sorry... That's just some plain ol' bad advice, Paul. Table Variables can be a huge performance problem if any size to them occurs especially since the optimizer sees them as a single row. I'll agree that "It Depends" but making a blanket statement to use table variables whenever possible is just flat out wrong. 😉

    Agreed Jeff, point taken. I should have included some wording to better describe the "whenever possible" part of it. 😉

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Hi Jeff, the blocking query from all blocking transactions report is:

    INSERT #StateInterval (

    ManagedEntityMonitorRowId

    ,IntervalStartDateTime

    ,IntervalEndDateTime

    ,HealthState)

    SELECT

    l.ManagedEntityMonitorRowId

    ,CASE WHEN l.[DateTime] <

    @IntervalStartDateTime

    THEN @IntervalStartDateTime

    ELSE l.[DateTime]

    END

    ,CASE WHEN ISNULL(r.

    [DateTime], '99991231') >

    @IntervalEndDateTime

    THEN @IntervalEndDateTime

    ELSE r.[DateTime]

    END

    ,CASE WHEN l.NewHealthState >

    ISNULL(r.OldHealthState,

    l.NewHealthState)

    THEN l.NewHealthState

    ELSE ISNULL(r.OldHealthState,

    l.NewHealthState)

    END

    FROM #StateEvent l

    LEFT JOIN #StateEvent r ON

    (l.ManagedEntityMonitorRowId =

    r.ManagedEntityMonitorRowId) AND (l.

    [DateTime] < r.[DateTime])

    WHERE (NOT EXISTS (SELECT *

    FROM #StateEvent m

    WHERE

    (l.ManagedEntityMonitorRowId =

    m.ManagedEntityMonitorRowId)

    AND (m.[DateTime] >

    l.[DateTime])

    AND (m.[DateTime] <

    ISNULL(r.[DateTime], '99991231'))

    )

    )

    AND (l.[DateTime] <

    @IntervalEndDateTime)

    -- "WHEN MAX(i2.HealthState) IN (1, 50) THEN 1" added below to aid

    -- in cases where many HSs are unavailable - it takes to long

    -- to figure out if monitor/me still exist and we know it'll

    -- be figured out anyways on next interval since "previous"

    -- interval end states 1 and 50 are eliminated from calculations

    This is the longest statement in explicit transaction, there are 400 statements in the transaction. (I captured the statements in profiler and looked between begin tran and commit from this SPID.)

    Is there a possibility to rescue the system tables from being locked?

  • I'd wait for others to comment but I'm not sure I would perform a transaction of that size on temporary tables to begin with..how long does it take for the whole process to run? and is your transaction being blocked by anything also?

  • are you creating the temp table(s) itself within an open transaction ? (avoid if possibible)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • I absolutely agree with the above. You should just about never include a temp table in a transaction especially (but not limited to) the creation of a temp table.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yes, its create #temp in an explicit transaction, at one point an insert to temp table takes 30 minutes, so locking sys.partitions.. The queries are coming from System Center Operations Manager itself..

  • What I'm trying to figure out is if the blocking unavoidable in these circumtances? Should I contact with SCOM support? This does not look as SQL's fault..

  • Is the SCOM query being blocked by anything?

    I don't recall any inserts (or anything really) taking 30 minutes in my setup.

  • The case is, there is an sp named OperationsManagerDW.dbo.StandardDatasetMaintenance in OperationsManagerDW, which is called periaodically every 1 hour or so, this call blocks tempdb because of temp tables, and meanwhile SCOM db monitor tries sp_spaceused for tempdb (to give alert about tempdb size), but it is blocked, then we have an BlockedSP alert in SCOM each 15 minutes.. (a bit complicated I guess if I did not got it wrong)

  • sporoy (9/13/2010)


    What I'm trying to figure out is if the blocking unavoidable in these circumtances? Should I contact with SCOM support? This does not look as SQL's fault..

    It's not SCOM's fault either. It's the fault of who ever that made the mistake of putting a temp table in an explicit transaction. That code MUST be repaired or removed.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Use this statement at the top of your query:

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

    This will make any table look up perform the same as the Hint (With NOLOCK) on each Join

    The only drawback is that it allows for Dirty reads on the table you are referencing so if your data is highly time sensitive, this may or may not work.

Viewing 15 posts - 1 through 15 (of 22 total)

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