监视由系统控制版本的内存优化时态表

适用于: SQL Server 2016 (13.x) 及更高版本 Azure SQL 托管实例

您可以使用现有视图来跟踪每个系统版本控制的内存优化表的详细和汇总内存消耗情况。

监视时态表

使用以下示例代码来监控使用内存内OLTP的时序表。 这些示例使用了常见的表表达式(CTE)。

详细的内存消耗

以下查询详细信息显示了内存消耗情况,并按主系统版本控制控制表和内部历史临时表分别列出。

WITH InMemoryTemporalTables
AS (SELECT SCHEMA_NAME(t1.schema_id) AS TemporalTableSchema,
           t1.object_id AS TemporalTableObjectId,
           t1.object_id AS InternalTableObjectId,
           OBJECT_NAME(t1.parent_object_id) AS TemporalTableName,
           t1.Name AS InternalHistoryStagingName
    FROM sys.internal_tables AS t1
         INNER JOIN sys.tables AS t1
             ON t1.parent_object_id = t1.object_id
    WHERE t1.is_memory_optimized = 1
          AND t1.temporal_type = 2)
SELECT TemporalTableSchema,
       t.TemporalTableName,
       t.InternalHistoryStagingName,
       CASE
           WHEN c.object_id = t.TemporalTableObjectId
           THEN 'Temporal Table Consumption'
           ELSE 'Internal Table Consumption'
       END AS ConsumedBy,
       c.*
FROM sys.dm_db_xtp_memory_consumers AS c
     INNER JOIN InMemoryTemporalTables AS t
         ON c.object_id = t.TemporalTableObjectId
         OR c.object_id = t.InternalTableObjectId
WHERE t.TemporalTableSchema = 'dbo'
      AND t.TemporalTableName = 'FXCurrencyPairs';

内存消耗摘要

以下查询汇总了内存消耗量,以及由系统控制版本的内存优化表的总量。

;WITH InMemoryTemporalTables
AS (
    SELECT SCHEMA_NAME(t1.schema_id) AS TemporalTableSchema,
        t1.object_id AS TemporalTableObjectId,
        t1.object_id AS InternalTableObjectId,
        OBJECT_NAME(t1.parent_object_id) AS TemporalTableName,
        t1.Name AS InternalHistoryStagingName
    FROM sys.internal_tables t1
    INNER JOIN sys.tables t1
        ON t1.parent_object_id = t1.object_id
    WHERE t1.is_memory_optimized = 1
        AND t1.temporal_type = 2
    ),
DetailedConsumption
AS (
    SELECT TemporalTableSchema,
        t.TemporalTableName,
        t.InternalHistoryStagingName,
        CASE
            WHEN c.object_id = t.TemporalTableObjectId
            THEN 'Temporal Table Consumption'
            ELSE 'Internal Table Consumption'
        END AS ConsumedBy,
        c.*
    FROM sys.dm_db_xtp_memory_consumers c
    INNER JOIN InMemoryTemporalTables t
        ON c.object_id = t.TemporalTableObjectId
            OR c.object_id = t.InternalTableObjectId
)
SELECT TemporalTableSchema TemporalTableName,
    sum(allocated_bytes) AS allocated_bytes,
    sum(used_bytes) AS used_bytes
FROM DetailedConsumption
WHERE TemporalTableSchema = 'dbo' ANDTemporalTableName = 'FXCurrencyPairs'
GROUP BY TemporalTableSchema,
    TemporalTableName;