INF: How to Move Tempdb to a Different Device
ID: Q187824
|
The information in this article applies to:
-
Microsoft SQL Server version 6.5
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.
- Configure tempdb to temporarily reside in RAM. To do this, perform the
following steps:
- 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.
- Click the Configuration tab.
- 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.
- Prevent the master device or any other devices from being a default
device. To do this, perform the following steps:
- 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.
- Click to clear the Default Device check box, and then click Change Now.
- Repeat Steps a-b for any other default devices you may have, except
for the TEMPDEVICE created in Step 2 of this procedure.
- Shut down and restart SQL Server. Tempdb should now be in RAM and not on
the master device.
- 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.
- 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).
- 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:
- 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.
- On the Options tab, verify that the following options (which are
desirable in most cases) are set:
- Select Into/Bulk Copy is enabled.
- Truncate Log On Checkpoint is enabled.
- Single User is disabled.
- DBO Use Only is disabled.
- On the Database tab, in the Size box, click Expand.
- Under Data Device, select TEMPDEVICE.
- 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.
- Click Expand Now.
For more information on expanding the size of a database, see the
"Expanding or Shrinking Databases" topic in the SQL Server Books Online.
Moving Tempdb by Using ISQL
- Make sure you have a current backup of the Master.dat file.
- 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.
- 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:
- The sp_configure 'tempdb in ram' configuration option is specified in
MB, not 2-KB pages, as the 'memory' parameter is.
- 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.
- Shut down and restart SQL Server. Tempdb should now be in RAM and not on
the master device.
- Now use sp_configure to take tempdb back out of RAM:
sp_configure 'tempdb in ram', 0
go
reconfigure with override
go
- Shut down and restart SQL Server. Because master is no longer a default
device, tempdb will go onto your new device.
- 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.
- Verify that the following database options are set for tempdb:
- Select Into/Bulk Copy is enabled.
- Truncate Log On Checkpoint is enabled.
- Single User is disabled.
- DBO Use Only is disabled.
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.
For more information, see the following articles in the Microsoft Knowledge
Base:
Q115050
: INF: When to Use Tempdb In RAM
Q158586
: PRB: 'Temp_db' Device Causes Problems Starting SQL Server
Q141183
: PRB: Log Segment Moved to Device Incorrectly if Tempdb Expanded
Q110139
: INF: Causes of SQL Transaction Log Filling Up
Additional query words:
dev temp db
Keywords :
Version : WINNT:6.5
Platform : winnt
Issue type : kbhowto kbinfo
|