SQL SERVER – TempDB is Full. Move TempDB from one drive to another drive.

When TempDB is Full, I investigate capacity and usage before moving its files. A move requires a planned restart.

An overflowing storage cart stands beside a cramped alcove, with a spacious sunlit destination visible through the doorway.

The older filegroup error suggested backing up a log. That advice doesn’t apply to TempDB. Temporary data, log use, disk capacity and growth limits need separate investigations.

Check capacity before moving files

Inspect all TempDB data and log files, available disk space, growth settings, and the workload using them. Unlimited growth can’t create more disk space. A different drive is useful only when capacity and I/O arrangements support the change.

-- Read the current logical file names and locations first.
SELECT name, physical_name, size * 8.0 / 1024 AS size_mb
FROM tempdb.sys.database_files;

-- Administrator examples only. These names and paths must match your instance.
ALTER DATABASE tempdb MODIFY FILE
    (NAME = tempdev, FILENAME = N'D:\TempDB\tempdb.mdf');
ALTER DATABASE tempdb MODIFY FILE
    (NAME = templog, FILENAME = N'D:\TempDB\templog.ldf');

Plan the destination and restart

The SQL shows the original logical names as examples. Include every file on your instance. Create the destination folder and grant the SQL Server service account the required access before changing the metadata.

TempDB is recreated at startup. The new file paths take effect after the planned service restart. If the folder or permissions are wrong, startup can fail. Prepare a recovery procedure and a maintenance window first.

After restart, query the file paths again and verify normal operation. Retire former files only after proving that they are no longer in use.

Reference: Moving system database files.

Moving TempDB is not a substitute for capacity planning, it is one possible response to a measured storage problem.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Backup and Restore, SQL Data Storage, SQL Error Messages, SQL Scripts, SQL Server, SQL Server Security, SQL Stored Procedure, SQL TempDB
Previous Post
STUFF Boundaries: Insert Text and Handle NULL Results
Next Post
SQL SERVER – Fix: HResult 0x274D, SQLCMD Level 16, State 1 Error: Microsoft SQL Native Client : Login timeout expired

Related Posts

79 Comments. Leave new

  • Hi,

    i did run the above script. How long does it usually take when you encounter such a problem?
    Thanks

    Reply
  • Hi Pinal, Plz Suggest.. as per article >>> however, no changes are made to TempDB till SQL Server restarts… What to do if its peak hours…?

    Reply
    • There is no other choice than restart. That’s why planning is important so that this doesn’t appear at the first place.

      Reply
  • you can add a new data-file in that case to different filegroup.. it will not require any restart and no impact on busy prod server….

    Reply
    • Are you talking about TempDB.. Its not possible. Here is the error, if you try adding new FG.

      Msg 1826, Level 16, State 1, Line 3
      User-defined filegroups are not allowed on “tempdb”.

      Reply
  • Anilkumar Jantikar
    July 25, 2017 10:48 am

    Planning to move tempdb file from one file to another file .. Current drive having only 32 GB space and moving it into new drive which is having 70GB. I have just ran the Modify scripts for tempdb which is saying initial size 4 GB and auto growth 1 GB. total 8 files. as soon as i ran this alter statement my existing tempdb drive got full. is it normal behavior ,sql server hold new intial size in current database?

    Reply
  • Pinal, We could add another data file in different drive which has more space to resolve the issue.

    Reply
  • One of the server drive L: is full with temp datafiles, customer is not responding to restart the system, remaining drives also doesn’t have that much of free space , what would be suggest to resolve the issue,

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.