How to Resize tempdb

When you are setting up a new SQL Server machine you need to determine how big you should make tempdb.  Not an easy task to get it right out of the box.  If you make tempdb too small, then the tempdb data or log file will have autogrowth events, as tempdb needs more space. Every time tempdb grows SQL Server will need to pause activity for a short period of time while the system grows the tempdb files.  This means your application transactions will have to wait while these autogrow events occur.  On the flip side if your tempdb database is oversized then you are just wasting disk space. 

To make sure you size tempdb appropriately you should monitor the tempdb space usage.  If there are autogrowth events occurring after you have recycled SQL Server than you might want to increase the size of your tempdb data files.  If tempdb never uses most of the tempdb space, then you might want to consider decreasing the size of tempdb. 

In order to resize tempdb you can use the ALTER DATABASE command.  By using the ALTER DATABASE command, you can set the initial size of the tempdb data and/or log files.  Below is an example where I changed the initial size of my tempdb DATA and LOG file:

ALTER DATABASE tempdb
  MODIFY FILE (Name=tempdb_data, filesize = 100MB),   
  MODIFY FILE (NAME=tempdb_log , filesize = 20MB);

Keep in mind the new sizes specified do not take effect until you recycle SQL Server.

See all articles by Greg Larsen

Gregory Larsen
Gregory Larsen
Gregory A. Larsen is a DBA at Washington State Department of Health (DOH). Greg is responsible for maintaining SQL Server and other database management software. Greg works with customers and developers to design and implement database changes, and solve database/application related problems. Greg builds homegrown solutions to simplify and streamline common database management tasks, such as capacity management.

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles