Thursday, April 2, 2009

Moving the tempDB files once the disk is full

Problem Description

If we come across following errors in log file Source:
MSSQLSERVER Event ID: 17052
Description: The LOG FILE FOR DATABASE 'tempdb' IS FULL. Back up the TRANSACTION LOG FOR the DATABASE TO free up SOME LOG SPACE.

Solution Description

we need to make sure that TempDB is set to autogrow and we do not set a maximum size for TempDB. If the current drive is too full to allow autogrow events, then we can arrange a bigger drive, or add files to TempDB on another device (using ALTER DATABASE as described below and allow those files to autogrow. )

Move TempDB from one drive to another drive. There are major two reasons why TempDB needs to move from one drive to other drive.
1) TempDB grows big and the existing drive does not have enough space.
2) Moving TempDB to another file group which is on different physical drive helps to improve database disk read, as they can be read simultaneously.
We need to follow direction below exactly to move database and log from one drive (c:) to another drive (d:) and (e:).

Open Query Analyzer or SSMS and connect to your server.

Run this script to get the names of the files used for TempDB.

USE TempDBGOEXEC sp_helpfileGO

Results will be something like:
name fileid filename filegroup size------- ------ ---------------------------------------tempdev 1 C:\Program FilesMicrosoft SQL ServerMSSQLdatatempdb.mdf PRIMARY 16000 KB
templog 2 C:Program FilesMicrosoft SQL ServerMSSQLdatatemplog.ldf NULL 1024 KB

along with other information related to the database.
The names of the files are usually tempdev and templog by default.
These names will be used in next statement. Run following code, to move mdf and ldf files.

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
The definition of the TempDB is changed. However, no changes are made to TempDB till SQL Server restarts. Please stop and restart SQL Server and it will create TempDB files in new locations.

No comments:

Post a Comment