在 SharePoint Server 中檢視記錄資料庫的資料

適用于:yes-img-132013 yes-img-16 2016yes-img-192019 yes-img-se訂閱版本 no-img-sopMicrosoft 365 中的 SharePoint

注意事項

[!附註] 因為 SharePoint Server 2016 在 Internet Information Services (IIS) 中以網站形式運作,所以管理員與使用者均依賴瀏覽器提供的協助工具功能。 SharePoint Server 2016 支援所支援瀏覽器的協助工具功能。 如需詳細資訊,請參閱下列資源: > 在 SharePoint鍵盤快速鍵>Touch的 SharePoint>>協助工具中規劃瀏覽器支援> 協助工具指導方針。

SharePoint 記錄資料庫簡介

若要監視執行 SharePoint Server 2016 的伺服器和在伺服器上執行的服務,您可以直接存取各種記錄,例如 Windows Server 事件記錄檔、SharePoint 整合記錄服務 (ULS) 記錄 (也稱為追蹤記錄) 或使用量資料記錄。 您也可以移至 SharePoint Server 2016 SharePoint 管理中心網站來檢閱各種報告。 SharePoint Health Analyzer 報告包含伺服器或服務的規則。 管理 (診斷) 報表包含搜尋相關資訊。 Web 分析報表包含 Web 分析計量。 如需報表的詳細資訊,請 參閱在 SharePoint Server 2016 中檢視報表和記錄

所有之前提到的監視方法都有限制。 例如,Windows Server事件記錄檔、SharePoint ULS 記錄檔以及使用狀況資料記錄檔不會儲存在單一位置。 您必須移至不同的位置來尋找相關的記錄檔。 同樣地,雖然管理中心的報表包含最常用的評量和監視資訊,但是您無法將更多的監視資訊新增至這些報表,因為這些報表是預先定義的且無法變更。

您可以使用 SharePoint Server 2016 中的記錄資料庫來提高監視效率。 記錄資料庫是涵蓋整個伺服器陣列的存放庫,儲存了伺服器陣列中每一部伺服器的 SharePoint Server 2016 監視資訊。 記錄資料庫提供的選項,可讓您可在單一位置檢視和自訂各種監視資訊。 再者,記錄資料庫是唯一可以直接修改資料庫來自訂報表的 SharePoint Server 2016 資料庫。

注意事項

如需 SharePoint Server 2016 資料庫的詳細資訊,請參閱SharePoint Server 中的資料庫類型和描述

注意事項

[!附註] 資料庫的預設名稱是 SharePoint_Logging 。 您可以使用 Microsoft PowerShell 來變更預設名稱和 SharePoint 資料庫伺服器位置。 如需記錄資料庫名稱與資料庫伺服器位置的詳細資訊,請參閱 在 SharePoint Server 中設定 Usage and Health Data Collection

在單一位置儲存各種監視資訊可協助您有效率地監視 SharePoint Server 2016 伺服器與服務。 更重要的是,您可以根據記錄資料庫內部的資料表來建立自己的報表,以符合獨特的監視、報表以及疑難排解需求。 本文說明如何使用現有的資料表與檢視來建立報表。 您可能會希望撰寫自己的提供者以建立新的資料表。

注意事項

[!附註] SQL 檢視為虛擬資料表。 資料表與 SQL 檢視之間的差異在於您可以修改資料表內部的資料,但是您無法修改 SQL 檢視內部的資料。

您可以使用 SharePoint Server 2016 管理中心來設定匯入記錄資料庫的記錄。 如需如何設定記錄類別、記錄層級以及追蹤 (ULS) 記錄路徑的詳細資訊,請參閱在 SharePoint Server 中設定診斷記錄。 如需如何啟用寫入記錄資料庫之內容的詳細資訊,請參閱在 SharePoint Server 中設定 Usage and Health Data Collection。 如需如何指定記錄資料庫伺服器、名稱和資料庫驗證資訊、要寫入記錄資料庫的事件,以及記錄寫入記錄資料庫的頻率 (亦即與使用狀況資料庫匯入相關的計時器工作) 的詳細資訊,請參閱在 SharePoint Server 2016 中設定 SharePoint Health Analyzer 計時器工作

本文中的程序使用 SQL Server Management Studio 來存取記錄資料庫。 Management Studio 是 SQL Server 2008 的元件。

注意事項

[!附註] 若要存取記錄資料庫,您必須擁有 Windows 驗證 (建議) 或 SQL 驗證。 資料庫驗證資訊是設定於 SharePoint Server 2016管理中心。 如需驗證方法的詳細資訊,請參閱在 SharePoint Server 中設定 Usage and Health Data Collection

SharePoint 記錄資料庫中預先定義的 SQL 檢視

本節說明 SharePoint Server 2016 記錄資料庫內部的磁碟分割表格與 SQL 檢視,並包括下列三個程序:

  • 使用 SQL Server Management Studio 存取記錄資料庫

  • 從預設檢視來檢視記錄資訊

  • 使用 Excel 匯出和檢視記錄資料

記錄資料庫會針對每個類別的每日資料使用不同的磁碟分割表格。 例如,第一天的計時器工作使用狀況資料會寫入 dbo.TimerJobUsage_Partition0 資料表,而 32 天後的資料則會寫入 dbo.TimerJobUsageUsage_Partition31 資料表。 一天之內的記錄會寫入一個磁碟分割表格。 這表示就每個記錄類別而言,每個磁碟分割表格會儲存特定一天的記錄。

注意事項

[!附註] 分割區資料表與特定日期之間的對應,視記錄資料庫保留期間與將記錄寫入記錄資料庫的開始日期而定。 您可以觀察每個資料表內的時間資訊來取得對應。 例如,如果保留期間為 14 天,而今日的記錄是寫入分割區資料表 2,則明天的記錄將寫入分割區資料表 3,依此類推。 14 天之後,將刪除所有記錄,並從分割區資料表 0 開始將新記錄寫入這些分割區資料表。

您可以使用 Management Studio 中預先定義的 SQL 檢視,在單一位置檢視所有的監視資訊。 每個預先定義的檢視會從特定記錄類別的所有 32 個磁碟分割表格中收集資料。 例如,您可以檢視從 dbo.TimerJobUsage_Partition0dbo.TimerJobUsageUsage_Partition31 的 32 個資料表中的監視資訊。

若要存取預先定義的檢視,您必須存取 SharePoint Server 2016 記錄資料庫。 然後從記錄資料庫中,檢視監視資訊。

使用 Management Studio來存取記錄資料庫

  1. 確認執行此程序的使用者帳戶具備 db_owner 固定資料庫角色。

  2. 在工作列上,按一下 [開始],指向 [所有程式],按一下 [Microsoft SQL Server 2008] 或是已安裝的最新 Microsoft SQL Server 版本,然後按一下 [SQL Server Management Studio]

    注意事項

    [!附註] 如果您的伺服器上沒有 Management Studio,請重新安裝 SQL Server 2008,然後新增 Management Studio 元件。 如需詳細資訊,請參閱<安裝 SQL Server>。

  3. 在 [ 連接到伺服器 ] 對話方塊中,選擇 [ Database Engine]。 Then specify the server name, for example, ServerName\SharePoint. Select the authentication type ( Windows Authentication or SQL Server Authentication) that you configured through SharePoint Server 2016Central Administration. If it is SQL Server Authentication, specify the credentials for the database administrator. After the information is set, click Connect.

  4. Switch to the Object Explorer view by clicking View, and then clicking Object Explorer. Expand Databases to see the logging database that has default name SharePoint_Logging or a name that you configured in Central Administration.

  5. 或者,您也可以展開記錄資料庫來查看資料表和檢視。

從預設檢視來檢視記錄資訊

  1. 確認執行此程序的使用者帳戶具備 db_owner 固定資料庫角色。

  2. 在 Management Studio 中,使用上述程序移至記錄資料庫節點。

  3. Expand the Views node of the database to see the default views. Right-click the view — for example dbo.RequestUsage, and choose Select Top 1000 Rows.

    [選取前 1000 個資料列] 操作為下列 T-SQL 查詢指令碼:

    /****** Script for SelectTopNRows command from SSMS ******/
    SELECT TOP 1000 [PartitionId]
          ,[RowId]
          ,[LogTime]
          ,[MachineName]
          ,[FarmId]
          ,[SiteSubscriptionId]
          ,[UserLogin]
          ,[CorrelationId]
          ,[WebApplicationId]
          ,[ServerUrl]
          ,[SiteId]
          ,[SiteUrl]
          ,[WebId]
          ,[WebUrl]
          ,[DocumentPath]
          ,[ContentTypeId]
          ,[QueryString]
          ,[BytesConsumed]
          ,[HttpStatus]
          ,[SessionId]
          ,[ReferrerUrl]
          ,[ReferrerQueryString]
          ,[Browser]
          ,[UserAgent]
          ,[UserAddress]
          ,[RequestCount]
          ,[QueryCount]
          ,[QueryDurationSum]
          ,[ServiceCallCount]
          ,[ServiceCallDurationSum]
          ,[OperationCount]
          ,[Duration]
          ,[RequestType]
          ,[Title]
          ,[RowCreatedTime]
      FROM [SharePoint_Logging].[dbo].[RequestUsage]
    

    結果視窗就會顯示資料表類別 [要求使用狀況] 的前 1000 個資料列。

  4. You can modify the T-SQL query in the SQL editor window. For example, if there are more than 1000 rows in the tables, you might want to view the top 5000 rows. To do that, change the script by replacing "SELECT TOP 1000" with "SELECT TOP 5000", and then click Execute.

如果您想要使用 Management Studio 以外的工具來檢視記錄,您可以擷取檢視中的監視資訊,然後另存為文字檔案或 CSV 檔案。 下列程序將使用 Excel 做為範例。

使用 Excel 匯出和檢視記錄資料

  1. 確認執行此程序的使用者帳戶具備 db_owner 固定資料庫角色。

  2. 在 Management Studio 中,移至記錄資料庫節點。

  3. 展開 [檢視] 節點,在您要從中擷取資料的檢視上按一下滑鼠右鍵,然後按一下 [選取前 1000 個資料列]

  4. In the result window, right-click, and then click Select All. 然後以滑鼠右鍵按一下,然後按一下 [另 存結果...]

  5. 在 [儲存方格結果] 視窗中,指定您要儲存檔案的資料夾,將 [存檔類型] 指定為 CSV (逗號分隔),然後指定適當的檔案名稱。

  6. 在 Excel 中,按兩下 CSV 檔案加以開啟。

SharePoint 記錄資料庫中的自訂 SQL 檢視

在 SharePoint Server 2016 中的記錄資料庫可讓您以兩種方式建立自訂報表。 您可以結合現有資料表中的相關資訊來產生新檢視,或者您可以在記錄資料庫內部撰寫提供者以產生新的磁碟分割表格。 本節中的範例僅會顯示第一種方式。

在使用狀況資料表和 ULSTraceLog 資料表中, CorrelationId 是疑難排解的重要參數。 這是因為每個錯誤訊息都包含唯一的 CorrelationIdCorrelationId 是一個 GUID,可用來連結有關某要求的所有相關資訊。 下列程序顯示如何使用 CorrelationId 來建立連結多個記錄類別的自訂檢視。

建立使用現有資料表的自訂 SQL 檢視

  1. 確認執行此程序的使用者帳戶具備 db_owner 固定資料庫角色。

  2. 在 Management Studio 中,移至記錄資料庫節點。

  3. In the logging database, expand the Views node. Choose one of the views for which you want to collect information. Right-click the view, and then click New View.

  4. In the Add Table window, choose the tables to add. For example, if you want to obtain information about feature usage site requests for a single day, you can add dbo.FeatureUsage_Partion1 and dbo.RequestUsage_Partion1.

    T-SQL 查詢會自動在這兩個資料表中內部聯結唯一索引鍵 PartionId

SELECT     
FROM   dbo.FeatureUsage_Partition1 INNER JOIN
    dbo.RequestUsage_Partition1 ON dbo.FeatureUsage_Partition1.PartitionId = dbo.RequestUsage_Partition1.PartitionId

  1. 以滑鼠右鍵按一下兩個資料表之間的連結,然後選取 [移除] 以中斷兩個資料表的聯結。

  2. 若要使用 CorrelationId 內部聯結這兩個資料表,請按一下其中一個資料表中的 CorrelationId 資料行,並將指標移至另一個資料表中的 CorrelationId 資料行。 也可以直接從 [查詢編輯器] 修改 SQL 查詢。

SELECT  
FROM   dbo.FeatureUsage_Partition1 INNER JOIN
    dbo.RequestUsage_Partition1 ON dbo.FeatureUsage_Partition1.CorrelationId = dbo.RequestUsage_Partition1.CorrelationId 

  1. 從每個資料表中選擇要在新的檢視中顯示的資料欄。

  2. Right-click and choose Execute SQL. The results appear in the result window.

另請參閱

概念

在 SharePoint Server 2016 中檢視報表與記錄檔

SharePoint Server 2016 監視概觀