【问题标题】:Where are the session definitions of extended events stored?扩展事件的会话定义存储在哪里?
【发布时间】:2013-03-22 04:03:38
【问题描述】:

是 msdb、resource、master 还是 local?如果我备份我运行 XE 的本地数据库,我是否也会备份我的会话?系统表中是否也存储了任何元数据? 谢谢大家。

【问题讨论】:

    标签: sql-server sql-server-2008 sql-server-2008-r2 extended-events


    【解决方案1】:

    您可以从各种扩展的 DMV 中检索它们。例如,下面的查询将返回一堆关于扩展事件的信息。包括一些被注释掉的过滤器:

    -- Extended Event Packages
    select
        name,
        guid,
        description
    from sys.dm_xe_packages
    where (capabilities is null or capabilities & 1 = 0) -- ignore private packages for SQL Server internal use
    
    -- Events
    select
        p.name as package_name,
        o.name as source_name,
        o.description
    from sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and o.object_type = 'event'
    --and o.name like 's%'
    
    -- Event targets
    select
        p.name as package_name,
        o.name as source_name,
        o.description
    from sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and o.object_type = 'target'
    
    -- Predicate sources
    select
        p.name as package_name,
        o.name as source_name,
        o.description
    from sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and o.object_type = 'pred_source'
    
    -- Predicate comparators
    select
        p.name as package_name,
        o.name as source_name,
        o.description
    from sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and o.object_type = 'pred_compare'
    
    -- Maps
    select
        p.name as package_name,
        o.name as source_name,
        o.description
    from sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and o.object_type = 'map'
    
    -- Types
    select
        p.name as package_name,
        o.name as source_name,
        o.description
    from sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and o.object_type = 'Type'
    
    -- Event columns
    select
        o.name as [event],
        oc.name as column_name,
        oc.column_type as column_type,
        oc.column_value as column_value,
        oc.description as column_description
    from
        sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
        inner join sys.dm_xe_object_columns as oc
            on o.name = oc.object_name
            and o.package_guid = oc.object_package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and (oc.capabilities is null or oc.capabilities & 1 = 0)
    and o.object_type = 'event'
    --and o.name like '%lock%'
    order by event, column_name
    
    
    -- Configurable Event Columns
    -- These elements are optional and usually not present in event output.
    -- They can be enabled as needed.
    select
        o.name as [event],
        oc.name as column_name,
        oc.column_type as column_type,
        oc.column_value as column_value,
        oc.description as column_description
    from
        sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
        inner join sys.dm_xe_object_columns as oc
            on o.name = oc.object_name
            and o.package_guid = oc.object_package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and (oc.capabilities is null or oc.capabilities & 1 = 0)
    and o.object_type = 'event'
    --and o.name = 'file_write_completed'
    and oc.column_type = 'customizable'
    
    -- Configurable options
    select
        oc.name as column_name,
        oc.column_id,
        oc.type_name,
        oc.capabilities_desc,
        oc.description
    from
        sys.dm_xe_packages as p
        inner join sys.dm_xe_objects as o
            on p.guid = o.package_guid
        inner join sys.dm_xe_object_columns as oc
            on o.name = oc.object_name
            and o.package_guid = oc.object_package_guid
    where
        (p.capabilities is null or p.capabilities & 1 = 0)
    and (o.capabilities is null or o.capabilities & 1 = 0)
    and (oc.capabilities is null or oc.capabilities & 1 = 0)
    and o.object_type = 'target'
    --and o.name = 'file_write_completed'
    and oc.column_type = 'customizable'
    
    -- Map Values
    select
        name,
        map_key,
        map_value
    from sys.dm_xe_map_values
    where 1 = 1
    --and name = 'wait_types' 
    --and map_value like 'lck%'
    

    【讨论】:

      【解决方案2】:

      经过一番挖掘后,我发现会话的定义存储在主数据库中(考虑到它是有道理的,因为会话是在服务器级别定义的)。

      备份此数据库将备份您创建的会话,但这不是恢复它们的最简单方法。您可能最好导出会话并将它们保存为模板,或者编写脚本并将它们保存在安全的地方。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-10
        • 2013-01-10
        • 1970-01-01
        相关资源
        最近更新 更多