Published on

June 7, 2016

How to Move TempDB to a New Drive in SQL Server

Have you ever encountered the issue of TempDB filling up and causing performance problems in your SQL Server? If so, you’re not alone. Many database administrators face this challenge and need to find a solution to move TempDB to a new drive. In this article, we will discuss the steps to accomplish this task.

Before we dive into the solution, let’s understand why moving TempDB to a new drive is necessary. There are two main reasons:

  1. Temp files can grow larger and the existing drive may not have enough space to accommodate them.
  2. Moving TempDB to a different physical drive can help improve database disk read performance.

Now, let’s move on to the step-by-step procedure to move TempDB to a new drive:

Step 1: Get Logical File Name

The first step is to obtain the logical file names for the TempDB data and log files. You can do this by executing the following script:

USE TempDB
GO
EXEC sp_helpfile
GO

By default, the logical file name for the TempDB data file is “tempdev” and for the log file is “templog”. These names may vary if you have made any customizations.

Step 2: Move TempDB to New Drive

Once you have the logical file names, you can proceed to move TempDB to the new drive. Execute the following scripts:

USE master
GO
ALTER DATABASE TempDB MODIFY FILE
(NAME = tempdev, FILENAME = 'd:\datatempdb.mdf')
GO
ALTER DATABASE TempDB MODIFY FILE
(NAME = templog, FILENAME = 'e:\datatemplog.ldf')
GO

After executing the above scripts, you will receive a message indicating that the query has run successfully. However, please note that the changes will only take effect after restarting the SQL Server services. Once the services are restarted, you will be able to see the changes in the location of the TempDB.

By following these simple steps, you can successfully move the TempDB to a new drive and avoid issues related to a full TempDB. It is important to be proactive in managing your database and taking necessary actions to ensure its smooth operation.

Thank you for reading this article. We hope you found it helpful in resolving the TempDB issue. Stay tuned for more SQL Server tips and tricks!

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.