Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Ryan Adams

Ryan Adams has worked for Verizon for 15 years. His primary focus is the SQL Server Engine, high availability, and disaster recovery. Previously he was a Senior Active Directory Architect and designed the company's worldwide Active Directory infrastructure. He serves on the Board of Directors for the North Texas SQL Server User Group and is President of the PASS Performance Virtual Chapter. He also serves as a Regional Mentor for PASS and holds the following certifications: MCP MCSA MCSE MCDBA MCTS MCITP.

How to move the TempDB Database

Note that TempDB is recreated every time SQL starts.  Why is this important?  It means we don’t have to move the physical file on the file system.

First we need to know the name and file location of the TempDB database files.  When you change the location, make sure to keep the same name.  Technically we don’t need the current physical path, but it’s just a good idea to have it documented in case things go badly.

SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID(N’tempdb’);
GO

Next we need to tell SQL where we plan to move the files.  Make sure to change the ”FILENAME” path and ensure the “NAME” is the same as what you got from the above query.

USE master;
GO
ALTER DATABASE TempDB
MODIFY FILE (NAME = Tempdev, FILENAME = ‘Y:\MSSQL10.MSSQLSERVER\MSSQL\DATA\tempdb.mdf’);
GO
ALTER DATABASE TempDB
MODIFY FILE (NAME = Templog, FILENAME = ‘Z:\MSSQL10.MSSQLSERVER\MSSQL\DATA\templog.ldf’);
GO

Now all we need to do is stop and restart SQL server.  Once SQL is back up you might want to run the first query again just to make sure everything went as planned and the location has been updated properly.  Also, don’t forget to clean up after yourself and delete the old database files.

More Information – If you are moving your TempDB database you might want to check out the following posts:

How to move the Master database

How to move the Model database

How to move the MSDB database

SQLAgent Error 435

How to move cluster Quorum drive

How to move cluster MSDTC drive

Comments

No comments.

Leave a Comment

Please register or log in to leave a comment.