Saturday, October 3, 2020

Move TempDB location for best SQL Server performance

We should move our TempDB to a faster drive for better performance.

Generally , when we install SQL Server by default and we do not customize it, it is quite possible that our TempDB is located on the same drive where our Operating System is installed. It is never a good idea to install any database on the same drive as Operating System. so we should move that TempDB to the another faster drive location.

To check the location of our TempDB, execute below store procedure.

USE TempDB
GO
EXEC sp_helpfile
GO

For moving this TempDB file location execute below query

Use Master
GO
ALTER DATABASE TempDB MODIFY FILE
(NAME= tempdev, FILENAME= 'D:\tempdb_mssql_1.mdf')
GO
ALTER DATABASE TempDB MODIFY FILE
(NAME= templog, FILENAME= 'D:\templog.ldf')
GO

After moving file to D:\ we should restart the SQL Server, other wise system will still pointing the old location. 

Note: Remember to check the security or permission of the new TempDB location.


No comments: