Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Tempdb issue Expand / Collapse
Author
Message
Posted Monday, May 17, 2010 5:12 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 5:18 AM
Points: 312, Visits: 532
Hi Experts,

i have an issue wen i create a temp table it take
1 sec to create a temp table in temp db also wen i check it from the perfmon
the active temp tables shows more the 16 lacs of temp table
the table name in the tempdb shows as this #table_________________
Post #922805
Posted Monday, May 17, 2010 10:03 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 5:54 AM
Points: 136, Visits: 337
temp tables are also created by other processes that perform sorts as part of their operation

Sql Server Blog
Sql Server Consultancy
Post #922987
Posted Tuesday, May 18, 2010 12:38 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 5:18 AM
Points: 312, Visits: 532
yes but wat i m staying here is

there is a procedure in which there are around 30 more procedure which are getting called

Eg create procedure abcdef
(

begin

exec ab ---doing some operations creatin 5 temp table doing some updation,insertion etc

exec abc ---doing some operations creatin 5 temp table doing some updation,insertion etc

exec abe ---doing some operations creatin 5 temp table doing some updation,insertion etc

exec abd ---doing some operations creatin 5 temp table doing some updation,insertion etc

end

)


what i know that after the procedure is exec the temp tables gets destroyed from the tempdb.
but here in this senario the temp tables are not getting getting destroyed from tempdb.
they are getting dropped wen the abcdef procedure gets executed completly.
Also wen we r running this procedure from different session we are getting blocking on tempdb
while creating a temp tables within the procedures
Post #923316
Posted Tuesday, May 18, 2010 3:32 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 21, 2014 5:54 AM
Points: 136, Visits: 337
looks like you are using global temporary tables which may cause blocking:

http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html


Sql Server Blog
Sql Server Consultancy
Post #923403
Posted Tuesday, May 18, 2010 5:48 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 5:18 AM
Points: 312, Visits: 532
no not using global temp tables ...
Post #923477
Posted Thursday, May 20, 2010 12:35 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 5:18 AM
Points: 312, Visits: 532
waiting for the reply...Jeff can u help in this process
Post #924840
Posted Thursday, May 20, 2010 5:27 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 1:01 PM
Points: 15,558, Visits: 27,932
Temp tables last for the length of the process that created them. That wrapper proc is the process, so as long as it's running, you'll keep those temp tables. You can explicitly drop temp tables too.

What are the procs doing? It doesn't sound like you're using the temp tables in an efficient manner.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #925005
Posted Thursday, May 20, 2010 5:49 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, February 11, 2011 8:31 PM
Points: 297, Visits: 277
Your process was involved in unresolved deadlock, therefore, the tables were not dropped and blocked the creating table process in tempdb.

This might be the bug in sqlserver 2005.

create proc proc1

as

begin

create table #abcd ( i int)

drop table #abcd

end

go



BEGIN TRAN

go

DECLARE @I INT

SET @I = 1

WHILE @I < 5000

BEGIN

EXEC proc1

SET @I = @I + 1

END

go

Select count(*) from tempdb.sys.tables

go


If you notice the last output, the tempdb now has 5000 temp tables. From a programmer perspective, as soon as a stored procedure finishes, the temp table scope is over and it is destroyed. In SQL2005 we do a deferred drop, but that doesn’t kick in until transaction is over.


Because of the begin tran command, the temp tables are not dropped and hence tempdb locks not released. However, these tables are no longer accessible even to the SPID which created it, but are still present in tempdb.

Saby DBA
Post #925018
Posted Thursday, May 20, 2010 6:00 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 5:18 AM
Points: 312, Visits: 532
yes saby i m gettin blocking in the tempdb.

Grant there are procedure with begin and tran
E.g
proc ssa
(
Begin tran
exec procedure1
-----create some temp table and do some updation,insertion etc on temp table and physical table as there are more than 5 tables in each proc ...

exec procedure2 -----create some temp table and do some updation,insertion etc on temp table and physical table as there are more than 5 tables in each proc ...

exec procedure3-----create some temp table and do some updation,insertion etc on temp table and physical table as there are more than 5 tables in each proc ...

commit

run with diffrent sessions got the blocking while creating a temp table
and one more thing is that the table creation takes 2 secs to create which is really more time.

it destroy the table after the 1 procedure get fully exec till commit.
Post #925025
Posted Thursday, May 20, 2010 6:26 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 1:01 PM
Points: 15,558, Visits: 27,932
Saby, I'm confused. Where did you get deadlocks in this situation. We're talking about blocking. That's not the same thing as deadlocks.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #925045
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse