Microsoft KB Archive/187824

= INF: How to Move Tempdb to a Different Device =

Article ID: 187824

Article Last Modified on 11/6/2003

-

APPLIES TO


 * Microsoft SQL Server 6.5 Standard Edition

-



This article was previously published under Q187824



SUMMARY
By default, tempdb is on the master device. You may want to move tempdb so that it resides entirely on another device. This article explains how to move tempdb onto a different device.



MORE INFORMATION
The basic procedure for moving tempdb to a different device is to first put tempdb in RAM, then make sure the device you want to put it on is the only default device (and has at least 2 MB of available space), and finally take tempdb back out of RAM. You can do this either from the SQL Enterprise Manager (SEM) GUI tool or by issuing ISQL commands. Each method is described below.

NOTE: Each method described here includes steps for creating a new device on which to place tempdb. However, you can also use an existing device, without creating a new one. If you want to use an existing device, skip the steps in the following procedures that deal with the creation of a new device and follow the rest of the steps. Also, if you decide to use an existing device, make sure it has at least 2 MB of free space available for when tempdb is moved back out of RAM.

Moving Tempdb by Using SQL Enterprise Manager
 Make sure you have a current backup of the Master.dat file. To do this, shut down SQL Server and copy the Master.dat file to another location. Start SQL Enterprise Manager. Create a new device for tempdb by doing the following:

 Right-click the Database Devices folder and click New Device on the shortcut menu. Alternatively, you can click Database Devices on the Manage menu and then click the New Device toolbar button. In the Name box, type the name "TEMPDEVICE" (without the quotation marks) and then click to select the Default Device option. In the Size box, type the number of megabytes you want your new device to be (for example, type 100 for a 100-MB device). Click Create Now.</ol> </li> Configure tempdb to temporarily reside in RAM. To do this, perform the following steps:

<ol style="list-style-type: lower-alpha;"> Right-click the server name and click Configure on the shortcut menu. Alternatively, you can click the Server menu, point to SQL Server, and then click Configure.</li> Click the Configuration tab.</li> Scroll down until you see the "tempdb in RAM (MB)" configuration option. In the Current column, type a number of megabytes of RAM to allocate to tempdb (for example, 2). This will only be temporary. Then click OK.</li></ol> </li> Prevent the master device or any other devices from being a default device. To do this, perform the following steps:

<ol style="list-style-type: lower-alpha;"> Under the Database Devices folder, double-click the master device or right-click the master device and click Edit on the shortcut menu. Alternatively, you can click Database Devices on the Manage menu, select the master device, and then click the Edit Device toolbar button.</li> Click to clear the Default Device check box, and then click Change Now.</li> Repeat Steps a-b for any other default devices you may have, except for the TEMPDEVICE created in Step 2 of this procedure.</li></ol> </li> Shut down and restart SQL Server. Tempdb should now be in RAM and not on the master device.</li> Take tempdb back out of RAM. To do this, repeat Step 3 of this procedure, but type 0 in the Current column for the "tempdb in RAM (MB)" configuration option.</li> Shut down and restart SQL Server again. Because master is no longer a default device, tempdb will go onto your new device that is specified as the default device (that is, TEMPDEVICE).</li> After restarting SQL Server, tempdb will have the default options set and a default size of 2 MB. You can change the tempdb database options and expand its size by performing the following steps:

<ol style="list-style-type: lower-alpha;"> Under the Databases folder, double-click tempdb or right-click tempdb and click Edit on the shortcut menu. Alternatively, you can click Databases on the Manage menu, select tempdb, and then click the Edit Database toolbar button.</li> On the Options tab, verify that the following options (which are desirable in most cases) are set:

<ul> Select Into/Bulk Copy is enabled.</li> Truncate Log On Checkpoint is enabled.</li> <li>Single User is disabled.</li> <li>DBO Use Only is disabled.</li></ul> </li> <li>On the Database tab, in the Size box, click Expand.</li> <li>Under Data Device, select TEMPDEVICE.</li> <li>In the Size (MB) box, type a number of megabytes to be added to tempdb. For example, if you type 8, it adds 8 MB to tempdb, for a total size of 10 MB.</li> <li>Click Expand Now.</li></ol>

For more information on expanding the size of a database, see the "Expanding or Shrinking Databases" topic in the SQL Server Books Online.</li></ol>

Moving Tempdb by Using ISQL
<ol> <li>Make sure you have a current backup of the Master.dat file.</li> <li> Create your new device for tempdb, using a statement similar to the following:

DISK INIT NAME = 'TEMPDEVICE', PHYSNAME = 'C:\MSSQL\DATA\TEMPDEV.DAT', SIZE = 51200, VDEVNO = 250 NOTE: This example creates a 100-MB device for tempdb. You can adjust the SIZE option as desired. </li> <li> Issue the following statements, which will put tempdb into RAM, prevent the master device from being a default device, and make the newly-created tempdevice into a default device:

sp_configure 'allow updates', 1 go     reconfigure with override go     sp_configure 'tempdb in ram', 2 go     sp_diskdefault master, defaultoff go     sp_diskdefault tempdevice, defaulton go     reconfigure with override go NOTES:

<ul> <li>The sp_configure 'tempdb in ram' configuration option is specified in MB, not 2-KB pages, as the 'memory' parameter is.</li> <li>If you have other default devices, you should also run sp_diskdefault with the defaultoff option for those devices as well. To see if you have other default devices, you can run the sp_helpdevice stored procedure.</li></ul> </li> <li>Shut down and restart SQL Server. Tempdb should now be in RAM and not on the master device.</li> <li> Now use sp_configure to take tempdb back out of RAM:

sp_configure 'tempdb in ram', 0 go     reconfigure with override go                       </li> <li>Shut down and restart SQL Server. Because master is no longer a default device, tempdb will go onto your new device.</li> <li> After restarting SQL Server, tempdb will have a default size of 2 MB. You can expand its size by using an ALTER DATABASE statement similar to the following:

ALTER DATABASE tempdb ON TEMPDEVICE = 8 This statement increases the size of tempdb by 8 MB, for a total size of 10 MB. For more information on the ALTER DATABASE statement, see the "ALTER DATABASE Statement" topic in the SQL Server Books Online. </li> <li>Verify that the following database options are set for tempdb:

<ul> <li>Select Into/Bulk Copy is enabled.</li> <li>Truncate Log On Checkpoint is enabled.</li> <li>Single User is disabled.</li> <li>DBO Use Only is disabled.</li></ul>

To do this, use the sp_dboption stored procedure. For more information on how to use sp_dboption to view or change database options, see the "sp_dboption System Stored Procedure" topic in the SQL Server Books Online.</li></ol>

For more information, see the following articles in the Microsoft Knowledge Base:

115050 : INF: When to Use Tempdb In RAM

158586 : PRB: 'Temp_db' Device Causes Problems Starting SQL Server

141183 : PRB: Log Segment Moved to Device Incorrectly if Tempdb Expanded

110139 : INF: Causes of SQL Transaction Log Filling Up

Additional query words: dev temp db

Keywords: kbhowto kbinfo KB187824

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.