Groups | Blog | Home
all groups > sql server connect > july 2003 >

sql server connect : cleanup the tempdb


Edgardo Valdez
7/1/2003 3:59:01 PM
Could be using a lot of cursors in your stored procedures?
If so, you might need to consider not relying so heavily
on them. These take a lot of resources in TEMPDB. Also,
make sure you DEALLOCATE them after you are done with them.

Are you using a lot of TEMP tables, particular large ones
holding SELECT * recordsets? A huge query loading a temp
table with millions of records can fill up TEMPDB quickly.
You always want to RESTRICT the size of recordsets in TEMP
tables. Only include the columns and rows you actually
need in the table, no more. To help speed these queries,
be sure the AUTOSTATS database option is turned on, and
then create one or more indexes on these temp tables that
can be used by your query. In many cases, you will find
that this can substantially speed up your application. But
like many performance tips, be sure you test this one to
see if it actually helps in your particular situation.
Also, do not use SELECT INTO to create your temp table, as
it places locks on system objects. Instead, create the
table using using standard DDL statements, and then use
INSERT INTO to populate the table. You should consider
using a clustered and non-clustered indexes on your temp
tables, especially for very large temp tables. You will
have to test to see if indexes help or hurt overall
performance. Also make sure you DROP your TEMP tables when
you are finished them as well.

If the temdb growing persists, I would consider putting
tempdb database on its own dedicated disk or array.By
isolating the tempdb database on its own disk, disk
contention is reduced and performance is increased. Since
the tempdb database does not need to be backed up, the
tempdb database can be located on a single disk, or for
best performance a RAID 0 array.


[quoted text, click to view]
Abraham
7/1/2003 6:01:01 PM
Is there currently a way to cleanup the tempdb?
Tried dbcc shrinkfile , but no luck.
Can't restart the server ,because it's on production.
What makes tempDB big ?
and tempDB is in Simple mode , but not truncating it .

Thanks

Andrew J. Kelly
7/1/2003 7:30:55 PM
Did you post to enough groups<g>? Tempdb is used for all sorts <pun
intended> of things during the normal operation of the database. What makes
it so big (by the way how big is it?) depends on what your doing but it is
most likely the result of a large join or sort operation. You might want to
check to see if you have a long running open tran as well. If it got that
big once it is most likely going to get that big again (unless it was a
mistake) so you shouldn't bother to shrink it until you know for sure. Next
time you see a lot of activity in it you can investigate to see what is
happening at the time with profiler, sp_who etc.

--

Andrew J. Kelly
SQL Server MVP


[quoted text, click to view]

<nntp>
7/2/2003 7:17:12 AM
if your applications are not explicitly using tempdb then the usage is
generally for sorting large queries.

[quoted text, click to view]

AddThis Social Bookmark Button