Default Trace

sql server trace 是一个轻量级的追踪工具,对追踪数据库的行为很有用,因此,sql server内置一个trace(default trace)。

1,sql server 内置Default Trace,Default Trace的TraceID是1,默认是开启的,可以通过sys.configurations 进行查看

select *
from sys.configurations
where configuration_id=1568

字段 value=1,表示Default Trace是开启的。

2,如果default trace没有开启,可以利用如下语句进行开启,或者关闭等操作。

--开启Default Trace
sp_configure ‘show advanced options‘ , 1 ;
GO
RECONFIGURE;
GO

sp_configure ‘default trace enabled‘ , 1 ;
GO
RECONFIGURE;
GO

--关闭Default Trace
sp_configure ‘default trace enabled‘ , 0 ;
GO
RECONFIGURE;
GO

sp_configure ‘show advanced options‘ , 0 ;
GO
RECONFIGURE;
GO

3,查看Default Trace的trace文件的存放路径,default trace的id是1

select *
from sys.traces
where id=1

Trace status: 0 = stopped ,1 = running

max_size:Maximum trace file size limit in megabytes (MB). This value is null when the trace is a rowset trace.

max_files:Maximum number of rollover files. This value is null if the Max number is not set.

系统默认提供5个跟踪文件,每一个文件的最大size默认是20MB,SQL Server负责维护这5个文件,当实例重启的时候或者到达文件最大值的时候,sql server生成新的文件,将最早的跟踪文件删除,依次滚动(rollover)更新。

4,查看trace 文件的内容

sys.fn_trace_gettable ( ‘filename‘ , number_files )

Be aware that the fn_trace_gettable function will not load rollover files (when this option is specified by using the number_files argument) where the original trace file name ends with an underscore and a numeric value. (This does not apply to the underscore and number that are automatically appended when a file rolls over.) As a workaround, you can rename the trace files to remove the underscores in the original file name. For example, if the original file is named Trace_Oct_5.trc and the rollover file is named Trace_Oct_5_1.trc, you can rename the files to TraceOct5.trc and TraceOct5_1.trc.

filename 能够从sys.traces 中获取。

select *
from sys.fn_trace_gettable(N‘C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log\log_4.trc‘,default)

5,查看default trace 追踪的Event 和 EventColumn

fn_trace_geteventinfo ( trace_id )

该函数返回 EventID 和 EventColumnID

select tgei.eventid,tgei.columnid
from sys.fn_trace_geteventinfo(1) tgei

查看default trace 追踪的Event详细信息,包括 Catagory,EventName 和 Column

select categ.name as CategoryName,
    te.trace_event_id as EventID,
    te.name as EventName,
    tc.trace_column_id as EventColumnID,
    tc.name as ColumnName,
    tc.type_name as ColumnType
from sys.fn_trace_geteventinfo(1) as gei
inner join sys.trace_columns tc
    on gei.columnid=tc.trace_column_id
inner join sys.trace_events te
    on gei.eventid=te.trace_event_id
inner join sys.trace_categories categ
    on te.category_id=categ.category_id
order by CategoryName,EventID,EventColumnID

6,查看Event和其Category,Category用于组织Event。在SQL Server 2012中,共有21个Category,180个Event,每个Event属于唯一的一个Category。

select tc.name as CategoryName,
    te.trace_event_id as EventID,
    te.name as EventName
from sys.trace_categories tc
inner join sys.trace_events te
    on tc.category_id=te.category_id
order by CategoryName

7,查看Event的Column,在SQL Server 2012中,共有66个Column,并不是每个Event都能绑定所有66个column,每个Event能够绑定的Column是固定的。
The sys.trace_event_bindings catalog view contains a list of all possible usage combinations of events and columns. For each event listed in the trace_event_id column, all available columns are listed in the trace_column_id column. Not all available columns are populated each time a given event occurs.

select te.trace_event_id as EventID,
    te.name as EventName,
    tc.trace_column_id as EventColumnID,
    tc.name as ColumnName,
    tc.type_name as ColumnType
from sys.trace_event_bindings teb
inner join sys.trace_columns tc
    on teb.trace_column_id=tc.trace_column_id
inner join sys.trace_events te
    on teb.trace_event_id=te.trace_event_id
order by EventID,EventColumnID

参考doc:

Server-wide Configuration Catalog Views (Transact-SQL)

System Trace Functions

时间: 2024-08-28 17:20:21

Default Trace的相关文章

Oracle的跟踪文件(trace file)

跟踪文件通常都是因为通过DBMS_MONITOR(在Oracle Database 9i Relese 2)及更早版本中则是ALTER SESSION SET SQL_TRACE=TRUE启用了跟踪的结果,或者是通过10046事件使用扩展的跟踪工具生成的,如下 这些跟踪文件包含与诊断和性能有关的信息.它们对于了解数据库应用的内部工作有着非凡的意义.在一个正常运行的数据库中,你会经常看到这些跟踪文件,而且远比看到其他类型的跟踪文件多得多. 1 文件位置 不论是使用DBMS_MONITOR.SQL_

SQL Server中关于跟踪(Trace)那点事

前言 一提到跟踪俩字,很多人想到警匪片中的场景,同样在我们的SQL Server数据库中“跟踪”也是无处不在的,如果我们利用好了跟踪技巧,就可以针对某些特定的场景做定向分析,找出充足的证据来破案. 简单的举几个应用场景: 在线生产库为何突然宕机?数百张数据表为何不翼而飞?刚打好补丁的系统为何屡遭黑手?新添加的信息表为何频频丢失?某张表字段的突然更改,究竟为何人所为?这些个匿名的访问背后,究竟是人是鬼?突然增加的增量数据,究竟是对是错?数百兆的日志爆炸式的增长背后又隐藏着什么?这一且的背后,是应用

oracle之 利用 controlfile trace文件重建控制文件

一. 11g RAC 重建控制文件 1. --"create controlfile"命令生成到追踪文件中:alter database backup controlfile to trace; 2. --确认追踪文件的路径:SQL> select value from v$diag_info where name='Default Trace File'; 3. -- 截取脚本 在追踪文件中找到并执行NORESETLOGS版本的"create controlfile&

DLT(Diagnostic Log and Trace)嵌入式系统程序运行记录

http://blog.csdn.net/yanlinembed/article/details/49837975 DLT的使用有属于Application范畴与Context范畴.在使用DLT时,需要包含以下头文件: #include <dlt/dlt.h> 1 1 同时需要link相应的dlt库文件. Context范畴需要使用以下statement去申明及注册: DLT_DECLARE_CONTEXT(BCcontext); // declare the context name. DL

SQL Server中关于跟踪(Trace)那点事(转载)

前言 一提到跟踪俩字,很多人想到警匪片中的场景,同样在我们的SQL Server数据库中“跟踪”也是无处不在的,如果我们利用好了跟踪技巧,就可以针对某些特定的场景做定向分析,找出充足的证据来破案. 简单的举几个应用场景: 在线生产库为何突然宕机?数百张数据表为何不翼而飞?刚打好补丁的系统为何屡遭黑手?新添加的信息表为何频频丢失?某张表字段的突然更改,究竟为何人所为?这些个匿名的访问背后,究竟是人是鬼?突然增加的增量数据,究竟是对是错?数百兆的日志爆炸式的增长背后又隐藏着什么?这一且的背后,是应用

Oracle 11g trace events

oracle的events,是我们在做自己的软件系统时可以借鉴的 Oracle 11g trace eventsORA-10001: control file crash event1ORA-10002: control file crash event2ORA-10003: control file crash event3ORA-10004: block recovery testing - internal errorORA-10005: trace latch operations fo

Oracle性能分析1:开启SQL跟踪和获取trace文件

当Oracle查询出现效率问题时,我们往往需要了解问题所在,这样才能针对问题给出解决方案.Oracle提供了SQL执行的trace信息,其中包含了SQL语句的文本信息,一些执行统计,处理过程中的等待,以及解析阶段(如生成执行计划)产生的信息.这些信息有助于你分解sql语句的服务时间和等待时间,并了解所用资源和同步点的详细信息,从而帮助你诊断存在的性能问题. 这篇文章介绍了怎么开启SQL跟踪和获取trace文件,详细信息如下. 开启SQL跟踪 从内部技术细节看,SQL跟踪是基于10046调试事件的

oracle学习----trace文件

1.查看v$diag_info视图,能查看跟踪文件的位置,具体的名称等信息. name列中,Diag Trace是11g跟踪文件所在位置 Default Trace File是当前会话的跟踪文件名 2.查询可以生成跟踪文件名select c.value||'\'||d.instance_name||'_ora_'||a.spid||'.trc'||case when e.value is not null then '_'||e.value end as tracefrom v$process

[转]Oracle DB 查看预警日志

"Database(数据库)"主页>"Related Links相关链接)"区域> "Alert Log Content (预警日志内容)" 查看预警日志 每个数据库都有一个alert_<sid >.log文件.此文件位于数据库所在的服务器中,如果设置了$ORACLE_BASE,则此文件默认存储在$ORACLE_BASE/diag/rdbms/<db_name>/<SID>/trace中. 数据库预