共用方式為


使用追蹤程序資料庫

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

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

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

追蹤哪些資料庫?

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

必要條件

附加資料庫

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

數據表層級共用

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

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

注意

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

範例

  1. 包含所有數據表。 不需要 『*』,因為所有數據表都預設會跟著:

    tablesToInclude = []
    
  2. 包含名稱開頭為 「Logs」 的所有資料表:

    tablesToInclude = ["Logs*"]
    
  3. 排除所有外部資料表:

    externalTablesToExclude = ["*"]
    
  4. 排除所有具體化檢視:

    materializedViewsToExclude=["*"]
    

資料庫名稱覆寫

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

使用 C 附加資料庫#

必要的 NuGet 套件

C# 範例

var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var followerSubscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
var resourceManagementClient = new ArmClient(credentials, followerSubscriptionId);
var followerResourceGroupName = "followerResourceGroup";
var followerClusterName = "follower";
var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
var resourceGroup = (await subscription.GetResourceGroupAsync(followerResourceGroupName)).Value;
var cluster = (await resourceGroup.GetKustoClusterAsync(followerClusterName)).Value;
var attachedDatabaseConfigurations = cluster.GetKustoAttachedDatabaseConfigurations();
var attachedDatabaseConfigurationName = "attachedDatabaseConfiguration"
var leaderSubscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var leaderResourceGroup = "leaderResourceGroup";
var leaderClusterName = "leader";
var attachedDatabaseConfigurationData = new KustoAttachedDatabaseConfigurationData
{
    ClusterResourceId = new ResourceIdentifier($"/subscriptions/{leaderSubscriptionId}/resourceGroups/{leaderResourceGroup}/providers/Microsoft.Kusto/Clusters/{leaderClusterName}"),
    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 tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var followerSubscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
var resourceManagementClient = new ArmClient(credentials, followerSubscriptionId);
var followerResourceGroupName = "testrg";
//The cluster and database attached database configuration are created as part of the prerequisites
var followerClusterName = "follower";
var attachedDatabaseConfigurationsName = "attachedDatabaseConfiguration";
var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
var resourceGroup = (await subscription.GetResourceGroupAsync(followerResourceGroupName)).Value;
var cluster = (await resourceGroup.GetKustoClusterAsync(followerClusterName)).Value;
var attachedDatabaseConfiguration = (await cluster.GetKustoAttachedDatabaseConfigurationAsync(attachedDatabaseConfigurationsName)).Value;
await attachedDatabaseConfiguration.DeleteAsync(WaitUntil.Completed);

使用 C 從領導者叢集卸離附加的追蹤者資料庫#

領導者叢集可以卸離任何鏈接的資料庫,如下所示:

var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var leaderSubscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
var resourceManagementClient = new ArmClient(credentials, leaderSubscriptionId);
var leaderResourceGroupName = "testrg";
var leaderClusterName = "leader";
var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
var resourceGroup = (await subscription.GetResourceGroupAsync(leaderResourceGroupName)).Value;
var cluster = (await resourceGroup.GetKustoClusterAsync(leaderClusterName)).Value;
var followerSubscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var followerResourceGroupName = "followerResourceGroup";
//The cluster and attached database configuration that are created as part of the Prerequisites
var followerClusterName = "follower";
var attachedDatabaseConfigurationsName = "attachedDatabaseConfiguration";
var followerDatabaseDefinition = new KustoFollowerDatabaseDefinition(
    clusterResourceId: new ResourceIdentifier($"/subscriptions/{followerSubscriptionId}/resourceGroups/{followerResourceGroupName}/providers/Microsoft.Kusto/Clusters/{followerClusterName}"),
    attachedDatabaseConfigurationName: attachedDatabaseConfigurationsName
);
await cluster.DetachFollowerDatabasesAsync(WaitUntil.Completed, followerDatabaseDefinition);

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

管理主體

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

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

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

管理權限

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

設定快取原則

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

備註

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

限制

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

後續步驟