Solved

SQL server tempdb expansion,shrinking

Posted on 2012-03-20
10
535 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
[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
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 12

Expert Comment

by:sachitjain
ID: 37741707
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
ID: 37741746
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
ID: 37741827
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37742167
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
ID: 37742204
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
 
LVL 12

Accepted Solution

by:
sachitjain earned 500 total points
ID: 37742276
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
ID: 37742348
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
ID: 37742386
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:Scott Pletcher
ID: 37742491
>> 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
ID: 37744467
If the BCP failed I expect it would have initiated a rollback reversing any changes to the temp database ....
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

623 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