The tempdb database is one of the system databases of SQL server, it is available for all users connected to that sql instance. "tempdb" is re-created every time the sql server instance is getting started. You don't have to physically move the data and log files.
Sometimes we're getting the error that drive is full.
Let's see how to change the tempdb file path.
Step1. First check the tempdb file path and name using below query
Step2. Now chose the filepath for new location of your tempdb. Now let's say you want to move tempdb to new drive (e.g. "H:\SQLFiles\SQLServer\")
After executing the above query, restart the sql instance. The files are created in the new location when the service is restarted. Until the service is restarted, "tempdb" continues to use the data and log files in existing location. You can delete the tempdb from previous location.
Sometimes we're getting the error that drive is full.
Msg 9002, Level 17, State 6, Line 1 The log fie for database 'tempdb' is full. Backup the transaction log for the database to free up some log space.
Let's see how to change the tempdb file path.
Step1. First check the tempdb file path and name using below query
USE tempdb; GO EXEC sp_helpfile; -- -- -- -- We'll get output like this
name | fileid | filename | filegroup | size | maxsize | growth | usage |
tempdev | 1 | PRIMARY | 8192 KB | Unlimited | 10% | data only | |
templog | 2 | NULL | 512 KB | Unlimited | 10% | data only |
Step2. Now chose the filepath for new location of your tempdb. Now let's say you want to move tempdb to new drive (e.g. "H:\SQLFiles\SQLServer\")
USE master; -- -- Now let's say you want to move tempdb to new drive (e.g. "H:\SQLFiles\SQLServer\") -- -- ALTER DATABASE tempdb MODIFY FILE (Name = tempdev, FileName='H:\SQLFiles\SQLServer\tempdb.mdf') GO ALTER DATABASE tempdb MODIFY FILE (Name = templog, FileName = 'H:\SQLFiles\SQLServer\tempdb.ldf')
After executing the above query, restart the sql instance. The files are created in the new location when the service is restarted. Until the service is restarted, "tempdb" continues to use the data and log files in existing location. You can delete the tempdb from previous location.
Comments
Post a Comment