Process not releasing tempdb space

  • Any suggestions on how to check why tempdb space is NOT being released?

  • Most likely you've come across a piece of bad application code that doesn't clean up after itself.

    All temporary objects created in tempdb must be dropped when you're done with them.

    You can check this by running a trace and looking at the actual SQL code. Anything that's created and not dropped at the end of a transaction is part of the problem.


    Kind regards,

    Vegard Hagen
    Norwegian DBA, occasional blogger and generally a nice guy who believes the world is big enough for all of us.
    @vegard_hagen on Twitter
    Blog: Vegards corner (No actual SQL stuff here - havent found my niche yet. Maybe some day...)

    It is better to light a candle than to curse the darkness. (Chinese proverb)
  • Vegard Hagen (10/22/2012)


    Most likely you've come across a piece of bad application code that doesn't clean up after itself.

    All temporary objects created in tempdb must be dropped when you're done with them.

    You can check this by running a trace and looking at the actual SQL code. Anything that's created and not dropped at the end of a transaction is part of the problem.

    So within a stored procedure, if i am creating any temp tables they should also be dropped? My understanding was temp tables are dropped after the session is completed?

  • sqldba_newbie (10/22/2012)


    Vegard Hagen (10/22/2012)


    Most likely you've come across a piece of bad application code that doesn't clean up after itself.

    All temporary objects created in tempdb must be dropped when you're done with them.

    You can check this by running a trace and looking at the actual SQL code. Anything that's created and not dropped at the end of a transaction is part of the problem.

    So within a stored procedure, if i am creating any temp tables they should also be dropped? My understanding was temp tables are dropped after the session is completed?

    In many cases that is true. Sometimes the temp table will not clean up after the session is closed. It is typically good practice to clean up these objects - it's only an extra line of code.

    That said, what do you mean by tempdb space not being released?

    Do you mean that tempdb data files and log file are full and the space is not being released internally or do you mean that tempdb is not shrinking and releasing space to the OS?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLRNNR (10/22/2012)


    sqldba_newbie (10/22/2012)


    Vegard Hagen (10/22/2012)


    Most likely you've come across a piece of bad application code that doesn't clean up after itself.

    All temporary objects created in tempdb must be dropped when you're done with them.

    You can check this by running a trace and looking at the actual SQL code. Anything that's created and not dropped at the end of a transaction is part of the problem.

    So within a stored procedure, if i am creating any temp tables they should also be dropped? My understanding was temp tables are dropped after the session is completed?

    In many cases that is true. Sometimes the temp table will not clean up after the session is closed. It is typically good practice to clean up these objects - it's only an extra line of code.

    That said, what do you mean by tempdb space not being released?

    Do you mean that tempdb data files and log file are full and the space is not being released internally or do you mean that tempdb is not shrinking and releasing space to the OS?

    tempdb data files and log file are full and the space is not being released internally

  • sqldba_newbie (10/23/2012)


    SQLRNNR (10/22/2012)


    sqldba_newbie (10/22/2012)


    Vegard Hagen (10/22/2012)


    Most likely you've come across a piece of bad application code that doesn't clean up after itself.

    All temporary objects created in tempdb must be dropped when you're done with them.

    You can check this by running a trace and looking at the actual SQL code. Anything that's created and not dropped at the end of a transaction is part of the problem.

    So within a stored procedure, if i am creating any temp tables they should also be dropped? My understanding was temp tables are dropped after the session is completed?

    In many cases that is true. Sometimes the temp table will not clean up after the session is closed. It is typically good practice to clean up these objects - it's only an extra line of code.

    That said, what do you mean by tempdb space not being released?

    Do you mean that tempdb data files and log file are full and the space is not being released internally or do you mean that tempdb is not shrinking and releasing space to the OS?

    tempdb data files and log file are full and the space is not being released internally

    Ok. So you will need to find what long running queries are consuming the space and holding onto the objects in tempdb.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • I work with several PowerBuilder developers and have the same issue. It is generally an open transaction on the tempdb. Tempdb will usually check point after I kill the open tran. I also use this script to quickly check free space.

    use tempdb

    DBCC OPENTRAN

    use tempdb

    SELECT DB_NAME() AS DbName,

    name AS FileName,

    size/128.0 AS CurrentSizeMB,

    size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0 AS FreeSpaceMB

    FROM sys.database_files;

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

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