Solved

SQL server tempdb expansion,shrinking

Posted on 2012-03-20
10
488 Views
Last Modified: 2012-04-10
Hi All,
I have a BCP load process which failed last night saying short of space at tempdb.
When I had a look this morning I have more than 120 GB free on the volume where tempdb is located. The total size of volume is 300GB.

The files on tempdb device are still of size 10GB. I configured them with "unrestricted Growth" so they should take remaining 120GB free when needed.

My question is "Why do I have an error in the first place"?
Does tempdb files shrink automatically after the transaction using them has finished?

Can I use any DMV to locate space usage for last 24 hours? If not how do I know what went wrong with last night's process?


Thanks
0
Comment
Question by:crazywolf2010
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Expert Comment

by:sachitjain
Comment Utility
TempDB gets filled up with many things:
1.> Temp tables
2.> Large table variables
3.> Intermediate query results during complex queries
4.> image of objects if you have enabled snapshot isolation level for your database/server
5.> Cursor processing..
6.> Other metadata

To control the size of tempdb you need to observe usage of all these features in your BCP program. Might be possible, there is some performance issue with your queries in BCP load process or you are using temp tables excessively.
0
 
LVL 12

Expert Comment

by:sachitjain
Comment Utility
Tuning your complex queries either by breaking them into pieces or by adding more indexes could actually improve the performance and reduce load on tempdb.
0
 

Author Comment

by:crazywolf2010
Comment Utility
Could you please answer to my specific queries below.

My question is "Why do I have an error in the first place"?
Does tempdb files shrink automatically after the transaction using them has finished?

Can I use any DMV to locate space usage for last 24 hours? If not how do I know what went wrong with last night's process?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Does tempdb files shrink automatically after the transaction using them has finished?
No.  You cannot set Tempdb to Auto-Shrink.
0
 

Author Comment

by:crazywolf2010
Comment Utility
OK that's great! So the question is, why did the tempdb didn't expand when it is set for autogrow and lot of space was free on the volume.

Is there any DMV which will show growth of tempdb file?

Thanks
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 12

Accepted Solution

by:
sachitjain earned 500 total points
Comment Utility
Yes it would shrink automatically once the transaction gets over. That's how it works. If your batch process failed last night saying short of space at tempdb then this only would be the reason. Try looking into current SQL Server log (Server->Management->SQL Server Logs->Current) on to your SQL server to check if you find anything regarding this error there.

Following link from MSDN could help you monitoring and troubleshooting insufficient disk space with tempdb.
http://msdn.microsoft.com/en-us/library/ms176029.aspx
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Yes it would shrink automatically once the transaction gets over
Care to post some documentation to back that up?  As I stated previously, you cannot set the tempdb to Auto-Shrink.
0
 
LVL 12

Expert Comment

by:sachitjain
Comment Utility
Agreed acperkins!

I think I wrote wrong statement earlier. There are 2 things:
1.> Size of tempdb
2.> Free space in tempdb

With end of each transaction, space allocated to internal objects of that transaction within tempdb would be released thus free space in temp db would increase.
Size you are right, it won't change automatically until we restart SQL server or shrink explicitly by dbcc shrinkdatabase or shrinkfile command. Somehow I messed up between free space and size. I apologize about that.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
>> have a BCP load process which failed last night saying short of space at tempdb. <<

Please post the *exact* error message(s).

And review the SQL Server error log; you very likely have additional error msgs there.

Verify that the tempdb *log* file is on a drive with additional space available, and that it is set to autogrow, and set to a fixed amount vs a percentage amount (such as 100M rather than 10%).
0
 
LVL 6

Expert Comment

by:SJCFL-Admin
Comment Utility
If the BCP failed I expect it would have initiated a rollback reversing any changes to the temp database ....
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now