一。可以用来收集的条件
1.client identifier --客户端表示,可以通过dbms_session.set_identifier来设置
2.Service
3.module ---指定一个模块
4.action ---指定一个行为,如insert,update等等
5.session
6.instance
二。详细使用说明
1.通过client identifier来收集执行信息
开始
EXECUTE DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(client_id => 'test');
结束
EXECUTE DBMS_MONITOR.CLIENT_ID_STAT_DISABLE(client_id => 'test');
2. 通过service_name,module,action收集信息的方法
收集service为testdb的my_mod模块的信息,模块的信息由应用开发者通过DBMS_APPICATION_INFO的SET_MODULE 和 SET_ACTION 存储过程去定制
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name => 'testdb',module_name => 'my_mod');
收集收集service为testdb的GLEDGER模块的insert动作信息
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name => 'testdb',module_name => 'my_mod', action_name => 'inserting');
结束信息收集就是将上面包的enable改为disable执行一边即可。
3.通过以下的视图查看收集后的信息
DBA_ENABLED_AGGREGATIONS ----这是一个全局视图
V$CLIENT_STATS
V$SERVICE_STATS
V$SERV_MOD_ACT_STATS
V$SVCMETRIC
V$CLIENT_STATS ---如果通过client_identifier来收集执行信息,可以通过这个视图查看结果
下面是一个通过client_id来收集执行信息的例子
session1 :
执行
SQL> exec dbms_session.set_identifier('test');
session2 :
执行
SQL> EXECUTE DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(client_id => 'test');
session1:执行一个sql语句
SQL> select count(*) from test;
COUNT(*)
----------
49761
session2 :查看V$CLIENT_STATS可以看到如下的信息,
1* select * from V$CLIENT_STATS
SQL> /
CLIENT_IDENTIFIER STAT_ID STAT_NAME VALUE
------------------------------ ---------- -------------------------------------------------- ----------
test 2882015696 user calls 4
test 3649082374 DB time 150628
test 2748282437 DB CPU 30029
test 63887964 parse count (total) 3
test 1431595225 parse time elapsed 77768
test 2453370665 execute count 7
test 2821698184 sql execute elapsed time 148951
test 85052502 opened cursors cumulative 3
test 3143187968 session logical reads 748
test 2263124246 physical reads 684
test 1190468109 physical writes 0
test 1236385760 redo size 0
test 582481098 user commits 0
test 3211650785 workarea executions - optimal 0
test 798730793 workarea executions - onepass 0
test 3804491469 workarea executions - multipass 0
test 3678609077 session cursor cache hits 0
test 3671147913 user rollbacks 0
test 916801489 db block changes 0
test 2877738702 gc cr blocks received 0
test 1759426133 gc cr block receive time 0
test 326482564 gc current blocks received 0
test 1388758753 gc current block receive time 0
test 2432034337 cluster wait time 0
test 3868577743 concurrency wait time 0
test 1099569955 application wait time 0
test 3332107451 user I/O wait time 136913
三。跟踪session
1.通过client_identifier来跟踪session
EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(client_id => 'OE.OE',waits => TRUE, binds => FALSE);
---waits 表示等待信息是否记录在trace文件中
---binds 表示是否记录绑定变量的信息
关闭
EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_DISABLE(client_id => 'OE.OE');
2.跟踪service,module,action
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(service_name => 'testdb',waits => TRUE, binds => FALSE, instance_name => 'testdb');
也可以指定模块名称
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(service_name => 'testdb',module_name => 'my_mod', waits => TRUE, binds => FALSE,instance_name => 'testdb');
以上两个列子的关闭方法
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(service_name => 'testdb',instance_name => 'testdb');
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(service_name => 'testdb',module_name => 'my_mod', instance_name => 'testdb');
3.通过session id去trace
EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(session_id => 144, serial_num => 154,waits => TRUE, binds => FALSE);
关闭
EXECUTE DBMS_MONITOR.SESSION_TRACE_DISABLE(session_id => 27, serial_num => 60);
如果是在当前用户模式下,可以直接输入
EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(waits => TRUE, binds => FALSE);
关闭
EXECUTE DBMS_SESSION.SESSION_TRACE_DISABLE();
4.trace整个实例
EXECUTE DBMS_MONITOR.DATABASE_TRACE_ENABLE(waits => TRUE, binds => FALSE,instance_name => ’testdb’);
关闭
EXECUTE DBMS_MONITOR.DATABASE_TRACE_DISABLE(instance_name => ’testdb’);
通过tkprof格式化trace文件后,即可查看
1.client identifier --客户端表示,可以通过dbms_session.set_identifier来设置
2.Service
3.module ---指定一个模块
4.action ---指定一个行为,如insert,update等等
5.session
6.instance
二。详细使用说明
1.通过client identifier来收集执行信息
开始
EXECUTE DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(client_id => 'test');
结束
EXECUTE DBMS_MONITOR.CLIENT_ID_STAT_DISABLE(client_id => 'test');
2. 通过service_name,module,action收集信息的方法
收集service为testdb的my_mod模块的信息,模块的信息由应用开发者通过DBMS_APPICATION_INFO的SET_MODULE 和 SET_ACTION 存储过程去定制
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name => 'testdb',module_name => 'my_mod');
收集收集service为testdb的GLEDGER模块的insert动作信息
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name => 'testdb',module_name => 'my_mod', action_name => 'inserting');
结束信息收集就是将上面包的enable改为disable执行一边即可。
3.通过以下的视图查看收集后的信息
DBA_ENABLED_AGGREGATIONS ----这是一个全局视图
V$CLIENT_STATS
V$SERVICE_STATS
V$SERV_MOD_ACT_STATS
V$SVCMETRIC
V$CLIENT_STATS ---如果通过client_identifier来收集执行信息,可以通过这个视图查看结果
下面是一个通过client_id来收集执行信息的例子
session1 :
执行
SQL> exec dbms_session.set_identifier('test');
session2 :
执行
SQL> EXECUTE DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(client_id => 'test');
session1:执行一个sql语句
SQL> select count(*) from test;
COUNT(*)
----------
49761
session2 :查看V$CLIENT_STATS可以看到如下的信息,
1* select * from V$CLIENT_STATS
SQL> /
CLIENT_IDENTIFIER STAT_ID STAT_NAME VALUE
------------------------------ ---------- -------------------------------------------------- ----------
test 2882015696 user calls 4
test 3649082374 DB time 150628
test 2748282437 DB CPU 30029
test 63887964 parse count (total) 3
test 1431595225 parse time elapsed 77768
test 2453370665 execute count 7
test 2821698184 sql execute elapsed time 148951
test 85052502 opened cursors cumulative 3
test 3143187968 session logical reads 748
test 2263124246 physical reads 684
test 1190468109 physical writes 0
test 1236385760 redo size 0
test 582481098 user commits 0
test 3211650785 workarea executions - optimal 0
test 798730793 workarea executions - onepass 0
test 3804491469 workarea executions - multipass 0
test 3678609077 session cursor cache hits 0
test 3671147913 user rollbacks 0
test 916801489 db block changes 0
test 2877738702 gc cr blocks received 0
test 1759426133 gc cr block receive time 0
test 326482564 gc current blocks received 0
test 1388758753 gc current block receive time 0
test 2432034337 cluster wait time 0
test 3868577743 concurrency wait time 0
test 1099569955 application wait time 0
test 3332107451 user I/O wait time 136913
三。跟踪session
1.通过client_identifier来跟踪session
EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(client_id => 'OE.OE',waits => TRUE, binds => FALSE);
---waits 表示等待信息是否记录在trace文件中
---binds 表示是否记录绑定变量的信息
关闭
EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_DISABLE(client_id => 'OE.OE');
2.跟踪service,module,action
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(service_name => 'testdb',waits => TRUE, binds => FALSE, instance_name => 'testdb');
也可以指定模块名称
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(service_name => 'testdb',module_name => 'my_mod', waits => TRUE, binds => FALSE,instance_name => 'testdb');
以上两个列子的关闭方法
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(service_name => 'testdb',instance_name => 'testdb');
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(service_name => 'testdb',module_name => 'my_mod', instance_name => 'testdb');
3.通过session id去trace
EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(session_id => 144, serial_num => 154,waits => TRUE, binds => FALSE);
关闭
EXECUTE DBMS_MONITOR.SESSION_TRACE_DISABLE(session_id => 27, serial_num => 60);
如果是在当前用户模式下,可以直接输入
EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(waits => TRUE, binds => FALSE);
关闭
EXECUTE DBMS_SESSION.SESSION_TRACE_DISABLE();
4.trace整个实例
EXECUTE DBMS_MONITOR.DATABASE_TRACE_ENABLE(waits => TRUE, binds => FALSE,instance_name => ’testdb’);
关闭
EXECUTE DBMS_MONITOR.DATABASE_TRACE_DISABLE(instance_name => ’testdb’);
通过tkprof格式化trace文件后,即可查看