共用方式為


使用追蹤程序資料庫

追蹤資料庫功能可讓您將位於不同叢集中的資料庫附加至 Azure 數據總管叢集。 後續資料庫會以只讀模式附加,讓您能夠檢視數據,並在內嵌至領導者資料庫的數據上執行查詢。 追蹤者資料庫會同步處理領導者資料庫中的變更。 由於同步處理,數據可用性會有幾秒鐘到幾分鐘的數據延遲。 時間延遲的長度取決於領導者資料庫元數據的整體大小。 領導者和追蹤者資料庫會使用相同的記憶體帳戶來擷取數據。 領導者資料庫擁有記憶體。 後續資料庫會檢視數據,而不需要擷取數據。 由於附加資料庫是只讀資料庫,因此除了快取原則、主體和許可權之外,無法修改資料庫中的數據、數據表和原則。 無法刪除附加的資料庫。 領導者或追蹤者必須先卸離資料庫,才能刪除。

使用追蹤程式功能將資料庫附加至不同的叢集,會作為基礎結構,在組織與小組之間共享數據。 此功能有助於隔離計算資源,以保護生產環境免於非生產使用案例。 追蹤程式也可以用來將 Azure 數據總管叢集的成本與對數據執行查詢的合作對象產生關聯。

注意

如需以舊版 SDK 為基礎的程式代碼範例,請參閱 封存一文

追蹤哪些資料庫?

下列適用於叢集:

  • 叢集可以遵循一個資料庫、數個資料庫或領導者叢集的所有資料庫。
  • 單一叢集可以追蹤來自多個領導者叢集的資料庫。
  • 叢集可以同時包含追蹤者資料庫和領導者資料庫。

必要條件

附加資料庫

您可以使用各種方法來附加資料庫。 在本文中,我們會討論使用 C#、Python、PowerShell 或 Azure Resource Manager 範本附加資料庫。 若要附加資料庫,您必須擁有使用者、群組、服務主體或受控識別,且領導者叢集和追蹤者叢集上至少有參與者角色。 使用 Azure 入口網站、PowerShellAzure CLIARM 範本新增或移除角色指派。 深入瞭解 Azure 角色型訪問控制 (Azure RBAC)不同的角色

注意

在附件程式期間建立追蹤資料庫時,不需要預先建立追蹤資料庫。

數據表層級共用

當您附加資料庫時,也會追蹤所有數據表、外部數據表和具體化檢視。 您可以藉由設定 『TableLevelSharingProperties』 來共用特定的數據表/外部數據表/具體化檢視。

'TableLevelSharingProperties' 包含八個字符串陣列:tablesToIncludetablesToExcludeexternalTablesToInclude、、externalTablesToExcludematerializedViewsToIncludematerializedViewsToExcludefunctionsToIncludefunctionsToExclude。 所有陣列中的項目數目上限為100。

注意

  • 使用 『*』 所有資料庫表示法時,不支持數據表層級共用。
  • 包含具體化檢視時,也會包含其源數據表。

範例

下列範例包含所有數據表。 根據預設,所有數據表都會遵循,而不使用 『*』 表示法:

tablesToInclude = []

下列範例包含所有函式。 根據預設,所有函式都會遵循而不使用 『*』 表示法:

functionsToInclude = []

下列範例包含名稱開頭為 「Logs」 的所有資料表:

tablesToInclude = ["Logs*"]

下列範例包含所有外部資料表:

externalTablesToExclude = ["*"]

下列範例包含所有具體化檢視:

materializedViewsToExclude=["*"]

資料庫名稱覆寫

您可以選擇性地讓追蹤叢集中的資料庫名稱與領導者叢集不同。 例如,您可能想要將多個領導者叢集的相同資料庫名稱附加至追蹤者叢集。 若要指定不同的資料庫名稱,請設定 『DatabaseNameOverride』 或 'DatabaseNamePrefix' 屬性。

使用 C 附加資料庫#

必要的 NuGet 套件

C# 範例

var followerClusterId = KustoClusterResource.CreateResourceIdentifier(subscriptionId: "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx", resourceGroupName: "followerResourceGroup", clusterName: "follower");
var leaderClusterId = KustoClusterResource.CreateResourceIdentifier(subscriptionId: "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx", resourceGroupName: "leaderResourceGroup", clusterName: "leader");
var attachedDatabaseConfigurationName = "attachedDatabaseConfiguration";

var credentials = new ManagedIdentityCredential();
var resourceManagementClient = new ArmClient(credentials);
var followerCluster = resourceManagementClient.GetKustoClusterResource(followerClusterId);
var attachedDatabaseConfigurations = followerCluster.GetKustoAttachedDatabaseConfigurations();
var attachedDatabaseConfigurationData = new KustoAttachedDatabaseConfigurationData
{
    ClusterResourceId = leaderClusterId,
    DatabaseName = "<databaseName>", // Can be a specific database name in a leader cluster or * for all databases
    DefaultPrincipalsModificationKind = KustoDatabaseDefaultPrincipalsModificationKind.Union,
    Location = AzureLocation.NorthCentralUS
};

// Table level sharing properties are not supported when using '*' all databases notation.
if (attachedDatabaseConfigurationData.DatabaseName != "*")
{
    // Set up the table level sharing properties - the following is just an example.
    attachedDatabaseConfigurationData.TableLevelSharingProperties = new KustoDatabaseTableLevelSharingProperties();
    attachedDatabaseConfigurationData.TableLevelSharingProperties.TablesToInclude.Add("table1");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.TablesToExclude.Add("table2");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.ExternalTablesToExclude.Add("exTable1");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.ExternalTablesToInclude.Add("exTable2");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.MaterializedViewsToInclude.Add("matTable1");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.MaterializedViewsToExclude.Add("matTable2");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.FunctionsToInclude.Add("func1");
    attachedDatabaseConfigurationData.TableLevelSharingProperties.FunctionsToExclude.Add("func2");
}

await attachedDatabaseConfigurations.CreateOrUpdateAsync(WaitUntil.Completed, attachedDatabaseConfigurationName, attachedDatabaseConfigurationData);

確認資料庫已成功附加

若要確認資料庫已成功附加,請在 Azure 入口網站尋找附加的資料庫。 您可以確認資料庫已成功附加在 追蹤者領導者 叢集中。

檢查您的追蹤者叢集

  1. 流覽至追蹤叢集,然後選取 [ 資料庫]。

  2. 在資料庫清單中,搜尋新的唯讀資料庫。

    入口網站中只讀追蹤資料庫的螢幕快照。

    您也可以在資料庫概觀頁面中檢視此清單:

    資料庫概觀頁面的螢幕快照,其中包含追蹤者叢集清單。

檢查您的領導者叢集

  1. 瀏覽至領導者叢集,然後選取 [ 資料庫]

  2. 檢查相關資料庫是否標示為 [與其他人>共用] 是

  3. 切換關聯性連結以檢視詳細數據。

    與其他人共用的資料庫螢幕快照,以檢查領導者叢集。

    您也可以在資料庫概觀頁面中檢視此專案:

    概觀的螢幕快照,其中含有與其他人共用的資料庫清單。

中斷連結追蹤資料庫

注意

若要從追隨者或領導者角色卸離資料庫,您必須擁有使用者、群組、服務主體或受管識別,且在您要卸離資料庫的叢集上至少具有貢獻者角色。 在下列範例中,我們使用服務主體。

使用 C# 將附加的追蹤者資料庫與追蹤者叢集中斷連結

追蹤者叢集可以中斷連結任何附加的追蹤者資料庫,如下所示:

var attachedDatabaseConfigurationId = KustoAttachedDatabaseConfigurationResource.CreateResourceIdentifier(
    subscriptionId: "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx", resourceGroupName: "testrg", clusterName: "follower",
    attachedDatabaseConfigurationName: "attachedDatabaseConfiguration");
var credentials = new ManagedIdentityCredential();
var resourceManagementClient = new ArmClient(credentials);
var attachedDatabaseConfiguration = resourceManagementClient.GetKustoAttachedDatabaseConfigurationResource(attachedDatabaseConfigurationId);
await attachedDatabaseConfiguration.DeleteAsync(WaitUntil.Completed);

使用 C 從領導者叢集中斷連結連結的追蹤者資料庫#

領導者叢集可以中斷連結任何連結的資料庫,如下所示:

var leaderClusterId = KustoClusterResource.CreateResourceIdentifier(subscriptionId: "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx", resourceGroupName: "testrg", clusterName: "leader");
var followerClusterId = KustoClusterResource.CreateResourceIdentifier(subscriptionId: "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx", resourceGroupName: "followerResourceGroup", clusterName: "follower");
var followerDatabaseDefinition = new KustoFollowerDatabaseDefinition(
    clusterResourceId: followerClusterId,
    attachedDatabaseConfigurationName: "attachedDatabaseConfiguration"
);
var credentials = new ManagedIdentityCredential();
var resourceManagementClient = new ArmClient(credentials);
var leaderCluster = resourceManagementClient.GetKustoClusterResource(leaderClusterId);
await leaderCluster.DetachFollowerDatabasesAsync(WaitUntil.Completed, followerDatabaseDefinition);

管理主體、許可權和快取原則

管理主體

附加資料庫時,請指定 「預設主體修改種類」。 預設值是結合覆寫授權主體與已授權主體的 領導者資料庫集合

種類 說明
聯盟 附加的資料庫主體一律會包含原始資料庫主體,以及新增至追蹤資料庫的其他新主體。
取代 原始資料庫沒有主體的繼承。 您必須為附加的資料庫建立新的主體。
沒有 附加的資料庫主體只包含原始資料庫的主體,沒有其他主體。

如需使用管理命令來設定授權主體的詳細資訊,請參閱 管理命令來管理追蹤者叢集

管理權限

管理唯讀資料庫許可權與所有資料庫類型的許可權相同。 若要指派許可權,請參閱管理 Azure 入口網站 中的資料庫許可權,或使用管理命令來管理資料庫安全性角色

設定快取原則

下列資料庫管理員可以修改 附加資料庫的快取原則 ,或裝載叢集上任何數據表的快取原則。 預設值是將領導者叢集資料庫和數據表層級快取原則中的源資料庫與資料庫和數據表層級覆寫原則中定義的原則結合在一起。 例如,您可以在領導者資料庫的 30 天快取原則上執行每月報告,以及追蹤者資料庫的三天快取原則,只查詢最近的數據以進行疑難解答。 如需使用管理命令在追蹤資料庫或數據表上設定快取原則的詳細資訊,請參閱 管理命令來管理追蹤者叢集

備註

檢閱下列附註:

  • 如果領導者/追蹤者叢集的資料庫之間發生衝突,當所有資料庫後面接著追蹤者叢集時,它們就會如下解決:
    • 在追蹤者叢集上建立名為 DB 的資料庫優先於在領導者叢集上建立的相同名稱的資料庫。 這就是為什麼追蹤叢集中的資料庫 DB 必須移除或重新命名,讓追蹤者叢集包含領導者的資料庫 DB
    • 從兩個以上的領導者叢集後面接著名為 DB 的資料庫,將任意從 其中一個 領導者叢集選擇,而且不會追蹤超過一次。
  • 顯示追蹤 叢集上執行叢集活動記錄和歷程記錄 的命令會顯示追蹤者叢集上的活動和歷程記錄,而其結果集不包含領導者叢集或叢集的結果。
    • 例如:.show queries 在追蹤者叢集上執行的命令,只會顯示在追蹤者叢集追蹤的資料庫中執行的查詢,而不會顯示在領導叢集中的相同資料庫上執行的查詢。

限制

查看下列限制條件:

  • 追蹤者和領導者叢集必須位於相同的區域中。
  • 如果在 所追蹤的資料庫上使用串流擷取 ,則串流擷取應啟用追蹤追蹤串流擷取數據。
  • 下列限制支援使用 客戶管理金鑰 進行資料加密的叢集 (CMK):
    • 追蹤者叢集或領導者叢集未追蹤其他叢集。
    • 如果追蹤者叢集追蹤已啟用 CMK 的領導者叢集,且領導者對密鑰的存取權被撤銷,則領導者和追蹤者叢集都會暫停。 在此情況下,您可以解決 CMK 問題,然後繼續追蹤者叢集,也可以中斷追蹤者資料庫與追蹤者叢集的卸離,並獨立於領導者叢集繼續。
  • 在卸離資料庫之前,您無法刪除附加至不同叢集的資料庫。
  • 在卸離叢集之前,您無法刪除已連結至不同叢集的叢集。
  • 在追蹤所有資料庫時,不支援數據表層級共用屬性。
  • 在追蹤資料庫中,若要查詢使用受控識別做為驗證方法的外部數據表,必須將受控識別新增至追蹤者叢集。 當領導者和追蹤者叢集布建在不同的租使用者中時,這項功能將無法運作。

後續步驟