Solved

SQl: Tempdb reserved space not being released

Posted on 2014-01-19
5
1,448 Views
Last Modified: 2014-03-18
Hi All,

We have a stored proc that seem to execute but never deallocate the space it reserves in tempdb.  During the stored proc it creates 7 temp tables each with about 100,000 - 200,00 rows and end of the proc it drops those tables and does a truncate of another table. As this stored proc runs a number of times a day the space increases..and then our monitoring system starts making noise.

Just to make matters more interesting there is a network device between the application servers and the sql server. This device does mutliplexing so there is not a 1:1 relationship between the application server connection pool, and the number of connections on the sql server. So this rules out issuing a hard connection close at the application end, which they are doing anyway.

The tempdb is fairly large, and to date it has not grown. This store proc would need to run for about 8 days with out intervention before the temp started growing. We pre-grew the tempdb.

Any suggestion on this one? I understand that as a stop gap we could check the DMV's and kill off any process matched a predefined profile, but I see that more as a temp work around not as the proper solution.

Cheers
JL
0
Comment
Question by:jaLouden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Assisted Solution

by:magarity
magarity earned 150 total points
ID: 39793214
First, let's make sure the culprit really is the stored proc you suspect.  Here is a query from technet that will show what processes are using how much space in tempdb. Run it when the stored proc is running:
SELECT t1.session_id, t1.request_id, t1.task_alloc,
  t1.task_dealloc, t2.sql_handle, t2.statement_start_offset, 
  t2.statement_end_offset, t2.plan_handle
FROM (Select session_id, request_id,
    SUM(internal_objects_alloc_page_count) AS task_alloc,
    SUM (internal_objects_dealloc_page_count) AS task_dealloc 
  FROM sys.dm_db_task_space_usage 
  GROUP BY session_id, request_id) AS t1, 
  sys.dm_exec_requests AS t2
WHERE t1.session_id = t2.session_id
  AND (t1.request_id = t2.request_id)
ORDER BY t1.task_alloc DESC

Open in new window

0
 
LVL 2

Author Comment

by:jaLouden
ID: 39793238
Hey Guru,

I can confirm it is  the stored proc. Our monitoring solution is about to show what SPID is using what in tempdb down to the individual file level.

I did however run the command just to be 100% sure..and use the monitoring tool and query match up.

Cheers
JL
0
 
LVL 35

Accepted Solution

by:
David Todd earned 150 total points
ID: 39793366
Hi,

What I'd do/What I've done:
With a couple of big ETL procedures, I've searched from the end of the file and found the last reference to temp file abc. After that, I've put an explicit if exits drop.

I did get a performance improvement in doing so, and not just letting the procedure end and delete the temp objects automatically.

HTH
  David

PS Template code for dropping a temp table
if object_id( N'tempdb..<temptable_name, sysname, #t>', N'U' ) is not null 
	drop table <temptable_name, sysname, #t>;

Open in new window

0
 
LVL 2

Author Comment

by:jaLouden
ID: 39793369
Hey David,

Will give that a go, looks good. Stay tuned.

Cheers
JL
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39793378
ah

Some of my last comment should be

... explicit if exists drop.

Regards
  David
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question