SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


expected tables in tempdb


expected tables in tempdb

Author
Message
ykffc
ykffc
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 14
May I ask this here?

Our different applications (stored proc) normally remove temp tables in the codes. I know sometimes one or two applications failed for various reasons. Question is: what happened to the temp table it creates if a process failed? Does it mean the specific temp tables a failed stored procedure creates will remain in the tempdb database? And under what ways those tables can be removed?

I heard the tempdb will get automatically re-create when sql server restarts. Does it mean these temp tables will be removed?

If I do not restart sql server, the temp tables will sit there, am I right?
If the temp tables sit there, how do I tell? Can I tell it by table names? If yes, what table names will be shown up when I explore the database in Manangement studio?

Note: the codes in a typical stored procedure of ours reads: create table $tmp ..blah blah blah.

The reason I ask this is because some processes we run are suddenly failing recently. And I suspect it has to do with the tempdb, but at this stage I am not 100% sure. If I examine the tempdb database now, I am seeing table names like #TEMP______________xxxx ( I mean a number of underscores and then xxxxxx, xxxxx are some random characters). I know many of our processes failed multiple times.

So these are some tables in my tempdb now and their names looks like this:
#TEMP____________xxxsxx
#TEMP____________xxsxsxx
..
#TEMP____________xxxxsddxx
and
#5c7dea2943
#4F3D49DCF1
#yyyyyyxx
..
..
#yyyyyyx

All those #yyyyy above are having similar filename format with #5c7dea2943, that is, some hex characters.

Thanks a lot.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)

Group: General Forum Members
Points: 418528 Visits: 47141
There are thee types of 'temp' tables, all stored in the tempDB database.

Global Temp Tables.

Created by CREATE TABLE ##MyTempTable AS ...
They are visible to all sessions. If not explicitly dropped, they are removed when all connections that reference them have disconnected from the server.
Visible in tempDB with the same name as they were created (##MyTempTable )

Local Temporary tables

Created by CREATE TABLE #MyTempTable AS ...
These are visible only to the connection that created them. If not explicity droped, they are dropped as soon as the connection that created them is closed, or the stored proc that created them completes (whichever occurs first)
Visible in tempDB with a name like #MyTempTable____________________________________________________________________________000000000002

Table variables

Created by DECLARE @myTableVar TABLE ...
Visible only in the scope they were created in. Dropped as soon as they go out of scope. Cannot be explicitly dropped.
Visible in tempdb with names like #0DAF0CB0

Does that clear things up?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


ddorfman-839533
ddorfman-839533
SSC-Addicted
SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)

Group: General Forum Members
Points: 420 Visits: 116
HI

Wondering if i can jump on the band wagon here. I have a sql 2008 server and i can see in my Tempdb - Temporary Tables section that the table variables #x26779u9 do not get removed . This is starting to clog up my tempdb , how do i remove these tables ?
reducedphatmike
reducedphatmike
SSC Veteran
SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)

Group: General Forum Members
Points: 223 Visits: 586
I'm having a similar issue. I am seeing these table variables get created, and in my case they are holding millions of rows, they do appear to get dropped, but it leaves behind about 65 gig of information in the tempdb log.

I've been restarting the sql server service to rebuild the tempdb from scratch, but I really need to try to find out why this is filling up the log so fast.
umar iqbal
umar iqbal
Right there with Babe
Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)

Group: General Forum Members
Points: 784 Visits: 395
if you want to clean up tempdb u can schedule this script. it will remove temp tables that are older than 12 hrs. u can schedule it hourly. test it in dev first since i grab it from website

--------------------------------------------

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N’[dbo].[TempTableToKeep]‘) AND OBJECTPROPERTY(id, N’IsUserTable’) = 1)
DROP TABLE [dbo].[TempTableToKeep]
GO
CREATE TABLE [dbo].[TempTableToKeep] (
[TempTable] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DateToDelete] [datetime] NOT NULL
) ON [PRIMARY]
GO

IF EXISTS (SELECT name FROM sysobjects WHERE name = N’sp_DropTempTables’ AND type = ‘P’)
DROP PROCEDURE sp_DropTempTables
GO
CREATE PROCEDURE sp_DropTempTables
AS
DECLARE @Cursor AS CURSOR
DECLARE @Name AS VARCHAR(100)
DECLARE @TableName AS SYSNAME
DECLARE @Owner AS VARCHAR(100)
DECLARE @SQL AS NVARCHAR(200)
SET @Cursor = CURSOR SCROLL FOR
SELECT tempdb.dbo.sysobjects.name, tempdb.dbo.sysobjects.*
FROM TempTableToKeep
RIGHT OUTER JOIN tempdb.dbo.sysobjects ON TempTableToKeep.TempTable = tempdb.dbo.sysobjects.name
WHERE ((tempdb.dbo.sysobjects.crdate < DATEADD(hh, -12, GETDATE())) AND (tempdb.dbo.sysobjects.type = ‘U’) AND (TempTableToKeep.DateToDelete < GETDATE())) OR
((tempdb.dbo.sysobjects.crdate < DATEADD(hh, -12, GETDATE())) AND (tempdb.dbo.sysobjects.type = ‘U’) AND (TempTableToKeep.DateToDelete IS NULL))
OPEN @Cursor
FETCH FIRST FROM @Cursor
INTO @Name, @Owner
WHILE (@@FETCH_STATUS = 0)
BEGIN
If (@@FETCH_STATUS = 0)
BEGIN
IF EXISTS(SELECT name FROM tempdb..sysobjects WHERE name = @Name AND type = ‘U’)
BEGIN
SET @SQL = ‘DROP TABLE tempdb..’ + @Name
–PRINT @SQL
EXECUTE sp_executesql @SQL
END
FETCH NEXT FROM @Cursor
INTO @Name
END
END
CLOSE @Cursor
DEALLOCATE @Cursor
GO

Crazy Alien

Umar Iqbal
umar iqbal
umar iqbal
Right there with Babe
Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)

Group: General Forum Members
Points: 784 Visits: 395
Just qurious what patch you hav eon sql and it it 32 bit or 64 bit?

Crazy Alien

Umar Iqbal
reducedphatmike
reducedphatmike
SSC Veteran
SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)SSC Veteran (223 reputation)

Group: General Forum Members
Points: 223 Visits: 586
64 bit SP2 build 3790
umar iqbal
umar iqbal
Right there with Babe
Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)Right there with Babe (784 reputation)

Group: General Forum Members
Points: 784 Visits: 395
apply sp3 if you can. is tempdb on raid 1?

Crazy Alien

Umar Iqbal
GilaMonster
GilaMonster
SSC Guru
SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)SSC Guru (418K reputation)

Group: General Forum Members
Points: 418528 Visits: 47141
umar iqbal (3/19/2009)
if you want to clean up tempdb u can schedule this script. it will remove temp tables that are older than 12 hrs.


Did you test out that script?

TempDB is set up in such a way that a particular connection can only drop temp tables that were created on that connection. if you try to drop a temp table that another connection created, you'll get an error similar to this:

select name from sys.tables
returns - #TEMP_______________________________________________________________________________________________________________000000000003

drop table tempdb..#TEMP_______________________________________________________________________________________________________________000000000003 returns

Cannot drop the table '#TEMP_______________________________________________________________________________________________________________000000000003', because it does not exist or you do not have permission.


The only time that script will work is if people are creating 'permanent' tables in tempDB.

Mike: Check that you don't have lots of open transactions. It also might be SQL caching the table's definitions, if they're frequently used. It's an optimisation in 2005 and higher. If temp tables or table variables (and what you have is a table variable) are frequently used then, instead of dropping them, SQL just 'truncates' them, leaving the definition. It saves the effort of recreating the table next time it's needed.

Are the tables being left with lots of rows in them? How are you checking that (since you can't query any temp table that you didn't create)? You mention 65 GB in the log, that'll just be from tempDB usage, not left over temp tables.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


ddorfman-839533
ddorfman-839533
SSC-Addicted
SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)

Group: General Forum Members
Points: 420 Visits: 116
Sorry i know im in the 2005 forum , but in have a sql 2008 server and there is only sp 1 for the server.
Using DBCC checkDB it returns that all tables have 0 rows , but what else would be slowing down my server . It seems as if there is almost a database or may be table level lock on the tables.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search