How to shrink TFS database size

前端 未结 3 1615
囚心锁ツ
囚心锁ツ 2021-01-05 01:24

We have a TFS2010 environment. The size is growing every week for a long time now.

We deleted a lot of old branches and team projects. We also used the test attachm

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 02:09

    After viewing unreasonable growth of the transaction log of the TFS database I couldn’t find the exact cause of the growth and couldn’t also control automatically shrinking of the log.

    Similar solution without the full database backup

    I tried this script several days on non-production server and only after i switched to production server.

    Ruining on SQL server 2012 & TFS 2015

    the following script automatically shrink the transaction log.

    Run this script after full back up using the SQL job

    Scripts parts:

    1) Disconnect all connection to specific database

    2) Switch Backup model to simple

    3) Set database log size to unlimited

    4) Shrink log file to 200mb (or any size you wish)

    5) Set max size to 50000 (or any size you wish)

    6) Set Backup model to full

    Script run takes about 3 -5 seconds on a 140GB DB

    USE [master]
    GO
    ALTER DATABASE [Tfs] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
    GO
    ALTER DATABASE [Tfs] SET RECOVERY SIMPLE WITH NO_WAIT
    GO
    ALTER DATABASE [Tfs] MODIFY FILE ( NAME = N'Tfs_log', MAXSIZE = UNLIMITED)
    GO
    
    USE [Tfs]
    GO
    DBCC SHRINKFILE (N'Tfs_log' , 200)
    GO
    
    ALTER DATABASE [Tfs] MODIFY FILE ( NAME = N'Tfs_log', MAXSIZE = 50000)
    
    USE [master]
    GO
    ALTER DATABASE [Tfs] SET RECOVERY FULL WITH NO_WAIT
    GO
    ALTER DATABASE [Tfs] SET MULTI_USER
    GO
    

提交回复
热议问题