Temp file not shrinking

Babawale Dawodu 110 Reputation points
2024-07-22T17:55:17.6866667+00:00

I have a temp DB file that is not shrinking. Temp DB has 6 mdf files but one is large and not shrinking after multiple attempts. Any idea on how to resolve this? Thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,949 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,651 questions
{count} votes

Accepted answer
  1. David Lundell 81 Reputation points
    2024-07-22T18:17:30.83+00:00

    Restarting the SQL Server service will cause the TempDB to be recreated at its original size.

    However, this may not be what you really hope to do. I frequently set TempDB to be as large as it ever gets so that queries don't need to be slowed down waiting on the database to grow.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Olaf Helper 44,941 Reputation points
    2024-07-22T17:58:46.07+00:00

    The counter question is: What's the problem with?

    If TempDB requries spaces, the it require it.

    So may after shrinking it will growth again ... because the space is required due to the workload.

    1 person found this answer helpful.

  2. CathyJi-MSFT 22,306 Reputation points Microsoft Vendor
    2024-07-23T03:46:56.0866667+00:00

    Hello @Babawale Dawodu ,

    What the error message that you got when you shrink tempdb?  

    By default, the tempdb database is configured to autogrow as needed. Therefore, this database may unexpectedly grow in time to a size larger than the desired size. Larger tempdb database sizes won't adversely affect the performance of SQL Server. When SQL Server starts, tempdb is re-created by using a copy of the model database, and tempdb is reset to its last configured size. 

    You can use below command to shrink tempdb. However, please note that DROPCLEANBUFFERS will remove all the procedure cache, which may slow down some systems right after as they have to rebuild all the procedure cache again. Again, shrink your TempDB ONLY if you are running out of the space or in crucial situations.

    CHECKPOINT
    GO
    DBCC FREEPROCCACHE
    GO
    DBCC SHRINKFILE (TEMPDEV, 1024)
    GO
    

    Or DBCC DROPCLEANBUFFERS: Clears out cached indexes and data pages.

    DBCC DROPCLEANBUFFERS WITH NO_INFOMSGS;
    GO
    

    We can use DBCC SHRINKDATABASE or DBCC SHRINKFILE to shrink tempdb, please refer to MS document Shrink the tempdb database to get detail information.

     Best regards,

    Cathy


    If the answer is helpful,  please click "Accept Answer" and kindly upvote it.

    1 person found this answer helpful.
    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.