Is it safe to delete temp files under C:\Windows\Temp on an SQL server?

AJ Diaz 1 Reputation point
2022-12-26T21:48:06.917+00:00

Is it safe to delete temp files under C:\Windows\Temp on an SQL server to free up space? Will there be SQL processes that are going to be affected if I delete these files? Will these temp files get deleted if the server (Windows Server 2012 R2) is restarted?

274118-tmp.png

SQL Server | Other
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2022-12-26T21:56:31.233+00:00

    Shouldn't be a problem. Files in use will be locked and would not be deleted. You could optionally run Disk Cleanup to clear them.

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    4 people found this answer helpful.

  2. Seeya Xi-MSFT 16,586 Reputation points
    2022-12-27T02:58:13.547+00:00

    Hi @AJ Diaz ,

    It's safe to delete anything in the Temp folder. Sometimes, you may get a "can't delete because the file is in use" message, but you can just skip those files.
    For safety, do your Temp directory deleting just after you reboot the computer. Sometimes, a program installer will put something in the Temp directory that it needs to complete the installation after a reboot. If you reboot and wait a bit so that everything has settled down, anything left in the Temp folder should be OK to delete.
    If you want to be conservative, use the built-in Disk Cleanup tool (type Disk Cleanup in the Search box). If you select "Temporary files" as one of the items to be cleaned (deleted), by default Disk Cleanup only deletes files that haven't been modified within the past 7 days.

    Best regards,
    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.
    0 comments No comments

  3. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2022-12-26T22:03:21.093+00:00

    SQL Server itself is not going to fall over if you start to purge files in C:\WINDOWS\TEMP. There is a faint risk that you have a CLR procedure, an extended stored procedure or similar that for some reason is dumping data for future use here. And for that matter it could be a regular stored procedure using xp_cmdshell. But not only is this unlikely, it would also be very bad practice.

    Will these temp files get deleted if the server (Windows Server 2012 R2) is restarted?

    I would not expect so. It has never happened on any of my machines, but they run Workstation OSs. However, the OS may offer a cleanup functionality. (Windows 10/11 do, but Windows Server 2012 R2 is older.)

    Personally, I delete files in my TEMP folders quite aggressively every now and then. What is a little noticeable in your case is that the files are that big. I would open one of them in an editor and see if could get a clue where they are coming from.

    1 person found this answer helpful.

  4. Docs 15,761 Reputation points
    2022-12-26T22:23:33.967+00:00

    These are some links to free up space for Windows 10 and 11 that may have some applications for sql-server:

    https://support.microsoft.com/en-us/windows/free-up-drive-space-in-windows-a18fae02-a0fa-8df9-9838-8970f9939de4

    https://www.tenforums.com/tutorials/83441-free-up-drive-space-windows-10-a.html

    .
    .
    .
    .
    .

    Please remember to vote and to mark the replies as answers if they help.

    On the bottom of each post there is:

    Propose as answer = answered the question

    On the left side of each post there is /\ with a number: click = a helpful post
    .
    .
    .
    .
    .

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.