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
Solved

SQL server tempdb expansion,shrinking

Posted on 2012-03-20
10
515 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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