TempDB is filling my C drive. How do I move it to another drive without losing anything?
TempDB is rebuilt every time SQL Server starts, so you only change its file paths. You do not copy the files. Follow these steps:
1. Execute SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('tempdb') to see the logical names.
2. Execute ALTER DATABASE tempdb MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf') for the data file.
3. Execute ALTER DATABASE tempdb MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf') for the log file. Repeat for every extra data file.
4. Make sure the folders exist and that the SQL Server service account has full control on them. If the account cannot control the new location, the instance fails to start.
5. Restart the SQL Server service.
6. Execute the first query again to confirm the new paths, then delete the old tempdb files from the C drive.
Does it matter if I use the same drive for the data and the log file?
It works, but separate drives reduce contention when the server is busy. Keep the same size for all tempdb data files and size them before the peak load, so the files do not grow during work. Test the change on a non production server first, because a wrong path stops the service from starting.
Moved to the E drive. The service started clean. Thanks.