【问题标题】:How to Shrink the TFS 2017 Fast Growing tbl_content Table如何缩小 TFS 2017 快速增长的 tbl_content 表
【发布时间】:2018-10-26 20:01:48
【问题描述】:

我们使用 TFS 2017 CI/CD 管道,效果很好。但是,TFS 2017 数据库平均每天增长约 1GB。截至 2018 年 10 月 23 日,一个数据库从 10GB 增长到 44GB。这种增长对我们来说慢慢变得不可持续。我们已经将保留政策调整到最低限度。

研究并阅读了至少 30 篇文章。以下是一些相关文章:

TFS tbl_Content started growing very fast after using VNext build

https://mattyrowan.com/2014/04/02/need-help-tfs-tbl_content-table-and-database-growth-out-of-control/

https://developercommunity.visualstudio.com/content/problem/63712/tfs-database-size.html

这是我到目前为止所做的:

  1. 反复审查保留政策,并减少到最低限度(1 天 1 份)。将“保持删除”调整为 10 天。

  2. 取消选中版本定义中的“保留构建”框

  3. 运行上述三篇文章的脚本,发现:

    a) FileContainer,有 149176 个文件,43GB,(34GB 压缩)

    b) FileContainerOwner:构建,29GB

所以增长的主要原因是构建(和工件)。

我的问题是如何缩小数据库大小?

我查看了构建定义下的“历史记录”和“已删除”选项卡。

  1. “历史记录”中的一些记录被“释放保留”锁定。我可以点击记录并删除。但它什么也没做。记录还在。

  2. “已删除”中的所有记录仍然存在。

所以再次回到我的问题,我如何删除这些记录以便可以回收空间?

谢谢。

【问题讨论】:

标签: tfs


【解决方案1】:

在将 RetainedByRelease 重置为 false 并等待至少 24 小时后,增长突增停止并且每天删除 tbl_content 中的条目。

总而言之,我也是这样做的:

  1. 在 nuget Microsoft.VisualStudio.Services.Client 之后使用 TFS REST API 将 RetainedByRelease 重置为 false

特别感谢这两个线程:

https://social.msdn.microsoft.com/Forums/vstudio/en-US/5f649821-b1bf-4008-bba9-0c960e124abb/tfs-releasemanagement-vnext-quotthis-build-has-been-retained-by-a-releasequot-issue?forum=tfsbuild

Trying to get list of TFS users trough client library

帮助开发者的完整源代码:

using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;

namespace TfsRestAPIs
{
    public class RestAPI
    {
        public static void UpdateRetainedByRelaseToFalse()
        {
            Uri tfsURI = new Uri("http://TFS2017:8080/tfs/YourProjectCollection");
            VssCredentials creds = new VssClientCredentials();
            creds.Storage = new VssClientCredentialStorage();
            VssConnection connection = new VssConnection(tfsURI, creds);
            var projectClient = connection.GetClient<ProjectHttpClient>();
            var projects = projectClient.GetProjects().Result;
            var buildClient = connection.GetClient<BuildHttpClient>();            

            foreach (var project in projects)
            {
                Log(project.Name);
                if (project.Name == "YourProjectName")
                {
                    var builds = buildClient.GetBuildsAsync(project.Id).Result;
                    foreach (Build build in builds)
                    {
                        if (build.BuildNumber.StartsWith("YourSearchCondition"))
                            try
                            {                                
                                if (build.RetainedByRelease.Value)
                                {
                                    Log(build.BuildNumber + "'s RetainedByRelease=true");
                                    build.RetainedByRelease = false;
                                    var res = buildClient.UpdateBuildAsync(build, build.Id).Result;
                                    Log("  --> RetainedByRelease is set to " + res.RetainedByRelease.Value);
                                }
                            }
                            catch (Exception e)
                            {
                                Log(build.BuildNumber + ":" + e.Message);
                            }
                    }
                }
            }
        }

        private static void Log(string msg)
        {
            Console.WriteLine(msg);
        }
    }
}

【讨论】:

    猜你喜欢
    • 2018-02-24
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2016-09-17
    • 2019-08-08
    • 2010-12-12
    • 1970-01-01
    • 2022-09-29
    相关资源
    最近更新 更多