当前位置:Gxlcms > 数据库问题 > ExtendEvent-判断DB是否有在使用

ExtendEvent-判断DB是否有在使用

时间:2021-07-01 10:21:17 帮助过:20人阅读

EVENT SESSION [DB_Usage] ON SERVER ADD EVENT sqlserver.sql_statement_completed(SET collect_statement=(1) ACTION(sqlserver.client_app_name,sqlserver.client_hostname, sqlserver.database_name,sqlserver.nt_username,sqlserver.sql_text,sqlserver.username) WHERE ([sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],NSDS_NONEDI_20190627) OR [sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],NWeb) AND [sqlserver].[nt_user]<>N‘AA\jinwei)) ADD TARGET package0.event_file(SET filename=ND:\XEvent\DB_Usage.xel) WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS, MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE, TRACK_CAUSALITY=OFF,STARTUP_STATE=ON) GO

 

解析数据

    select 
    SWITCHOFFSET(n.value(@timestamp,Datetime),+08:00) as EventTime,
    n.value((data[@name="duration"]/value)[1], int) as duration,
    n.value((data[@name="statement"]/value)[1], nvarchar(max)) as statement,
    n.value((action[@name="database_name"]/value)[1], nvarchar(128)) as database_name,
    n.value((action[@name="client_app_name"]/value)[1], nvarchar(128)) as client_app_name,
    n.value((action[@name="username"]/value)[1], nvarchar(128)) as username,
    n.value((action[@name="nt_username"]/value)[1], nvarchar(128)) as nt_username,

    n.value((action[@name="client_hostname"]/value)[1], nvarchar(128)) as client_hostname
from (select cast(event_data as XML) as event_data
from sys.fn_xe_file_target_read_file(D:\XEvent\DB_Usage_0*.xel, null, null, null)) ed
cross apply ed.event_data.nodes(event) as q(n)

 

ExtendEvent-判断DB是否有在使用

标签:color   arc   ali   mem   name   扩展   pack   targe   retention   

人气教程排行