一.相关说明
当我们在一个session 上进行事务操作时,如果我们想查看这个事务的相关统计信息,那么可以通过v$mystat ,v$sysstat, v$sesstat, v$statname 字典来查看。 在Oracle 11g中,通过这2个视图,我么可以查看到588个相关的统计信息。
- SQL> select * from v$version;
-
- BANNER
-
- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
- PL/SQL Release 11.2.0.1.0 - Production
- CORE 11.2.0.1.0 Production
- TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
- NLSRTL Version 11.2.0.1.0 - Production
-
- SQL> SELECT COUNT (*)
- 2 FROM v$mystat vm, v$sysstat vs
- 3 WHERE vm.statistic# = vs.statistic#;
-
- COUNT(*)
-
- 588
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> SELECT COUNT (*)
2 FROM v$mystat vm, v$sysstat vs
3 WHERE vm.statistic# = vs.statistic#;
COUNT(*)
----------
588
v$mystat 字典只能查看当前session 的信息,而v$sesstat 可以查看所有session 的信息,v$sysstat和v$statname 是对统计信息的一个说明。如果不是SYS 用户来执行,那么就需要单独的对这些用户进行赋权操作,具体命令如下:
- grant select on v_$mystat to anqing;
- grant select on v_$statname to anqing;
- grant select on v_$sesstat to anqing;
- grant select on v_$sysstat to anqing;
grant select on v_$mystat to anqing;
grant select on v_$statname to anqing;
grant select on v_$sesstat to anqing;
grant select on v_$sysstat to anqing;
有关Oracle 视图的相关说明参考:
Oracle 性能相关的几个 视图 和 参数
http://blog.csdn.net/tianlesoftware/article/details/5867276
Oracle 动态性能视图
http://blog.csdn.net/tianlesoftware/article/details/5863191
二.查看当前session 的统计信息:v$mystat 和v$sysstat
我们可以通过如果SQL 来查看当前session 的具体统计信息,从而来帮助我们分析SQL 语句:
- /* Formatted on 2012/6/25 10:57:20 (QP5 v5.185.11230.41888) */
- SELECT vm.sid, vs.name, vm.VALUE
- FROM v$mystat vm, v$sysstat vs
- WHERE vm.statistic# = vs.statistic#
- AND vs.name IN
- ('cleanouts only - consistent read gets',
- 'session logical reads',
- 'physical reads',
- 'physical reads direct',
- 'redo size');
-
/* Formatted on 2012/6/25 10:57:20 (QP5 v5.185.11230.41888) */
SELECT vm.sid, vs.name, vm.VALUE
FROM v$mystat vm, v$sysstat vs
WHERE vm.statistic# = vs.statistic#
AND vs.name IN
('cleanouts only - consistent read gets',
'session logical reads',
'physical reads',
'physical reads direct',
'redo size');
这个操作需要注意相关的权限问题。
三.查看所有session的统计信息:v$sessstat 和 v$statname
- /* Formatted on 2012/6/25 12:39:51 (QP5 v5.185.11230.41888) */
- SELECT a.sid, b.name, a.VALUE
- FROM v$sesstat a, v$statname b
- WHERE a.statistic# = b.statistic#
- AND b.name IN
- ('cleanouts only - consistent read gets',
- 'session logical reads',
- 'physical reads',
- 'physical reads direct',
- 'redo size');
/* Formatted on 2012/6/25 12:39:51 (QP5 v5.185.11230.41888) */
SELECT a.sid, b.name, a.VALUE
FROM v$sesstat a, v$statname b
WHERE a.statistic# = b.statistic#
AND b.name IN
('cleanouts only - consistent read gets',
'session logical reads',
'physical reads',
'physical reads direct',
'redo size');
这里我们也可以加上SID 条件,只查看某个session的的统计信息,获取SID的方法参考:
Oracle 查看当前会话 SESSION ID 方法 说明
http://blog.csdn.net/tianlesoftware/article/details/7240085
- SELECT a.sid, b.name, a.VALUE
- FROM v$sesstat a, v$statname b
- WHERE a.statistic# = b.statistic#
- AND sid = 139
- AND b.name IN
- ('cleanouts only - consistent read gets',
- 'session logical reads',
- 'physical reads',
- 'physical reads direct',
- 'redo size');
SELECT a.sid, b.name, a.VALUE
FROM v$sesstat a, v$statname b
WHERE a.statistic# = b.statistic#
AND sid = 139
AND b.name IN
('cleanouts only - consistent read gets',
'session logical reads',
'physical reads',
'physical reads direct',
'redo size');
四.所有的统计信息列表
在Oracle 11gR2中总共有588个相关的统计,我们可以根据自己的需要来查看相关的信息,这588个统计的所有列表如下: