How SQL Server removes redundant tempdb files

Source: Internet
Author: User
Tags microsoft sql server

At some point, more than one tempdb file has been created, and the server core number has been exceeded, and the tempdb file is deleted so that it remains the same as the number of CPU cores. However, when the deletion, found unable to delete, reported error: Cannot delete the file "Tempdev3", because it cannot be empty (Microsoft SQL Server, error: 5042)

  

In this case, use the script to view data and log file usage:

SELECT db_name() asDbname,name asfilename,size/128.0  ascurrentsizemb,size/128.0 - CAST(Fileproperty(Name,'spaceused') as INT)/128.0  asFreespacemb fromsys.database_files;

Can see tempdev3 This file has been occupied a part of the space, in the actual production, may each file will be occupied, here only for experimental purposes.

In this case, you need to shrink the Tempdev3 file in tempdb, before shrinking it, you need to make sure that the file does not have temporary files such as temporary tables, so you need to delete all of them before shrinking, shrinking the script:

 Use tempdb GO DBCC -- To empty "tempdev3" data file GO after the contraction is complete, delete the file with the following script: ALTER DATABASE    file-to-Delete "tempdev3" Data FILEGO  The excess files in tempdb are completely removed. 

How SQL Server removes redundant tempdb files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.