这里只是整理一下TOM的RUNSTATS检查工具包的脚本及使用示例,由于脚本内容较多,记录一下还是很必要的,便于日后使用翻看。
要运行RUNSTATSSS测试工具,必须有访问V$STATNAME,V$MYSTAT,V$LATCH的权限。
还必须有对SYS.V_$STATNAME,SYS.V_$MYSTAT,SYS.V_$LATCH的直接权限(不是通过角色授权)。
create or replace view stats
as
select 'STAT...'||a.NAME AS name, b.VALUE as value
from v$statname a, v$mystat b
where a.STATISTIC# = b.STATISTIC#
union all
select 'latch'||name as name, gets as value
from v$latch;
创建一张存储这些统计信息的小表:
create global temporary table run_stats
(
) on commit preserve rows;
-- 创建 runstats 包。其中包括 3 个简单 API 调用:
create or replace package runstats_pkg
as
end;
/
create or replace package body runstats_pkg
as
-- 这些全局变量用于纪录每次运行的耗用时间:
procedure rs_middle
procedure rs_stop(p_difference_threshold in number default 0)
and c.runid = ‘after 2’
end;
/
以上可以考虑在SYS用户下创建,之后创建runstats_pkg的public synonym即可。
使用实例:
使用Scott/tiger用户:
SQL> drop table heap;
表已丢弃。
SQL> drop table iot;
表已丢弃。
SQL> create table heap (dummy )
表已创建。
SQL> ed
已写入文件 afiedt.buf
SQL> /
表已创建。
SQL> analyze table heap compute statistics;
表已分析。
SQL> analyze table iot compute statistics;
表已分析。
SQL> exec runstats_pkg.rs_start;
PL/SQL 过程已成功完成。
SQL> ed
已写入文件 afiedt.buf
SQL> /
PL/SQL 过程已成功完成。
SQL> exec runstats_pkg.rs_middle;
PL/SQL 过程已成功完成。
SQL> ed
已写入文件 afiedt.buf
SQL> /
PL/SQL 过程已成功完成。
SQL> set serveroutput on size 1000000
SQL> exec runstats_pkg.rs_stop;
Run1 ran in7480hsecs
Run2 ran in3131hsecs
run 1 ran in 238.9%of the time
Name
STAT...SQL*Net roundtrips to/f
STAT...active txn count during
STAT...calls to kcmgcs
STAT...cleanout - number of kt
STAT...db block gets
STAT...opened cursors cumulati
STAT...user calls
latchktm global data
latchmessage pool operations p
latchsort extent pool
latchsimulator lru latch
latchsimulator hash latch
latchsession idle bit
latchobject stats modification
latchkwqit: protect wakeup tim
latchfile number translation t
STAT...parse count (failures)
STAT...free buffer requested
STAT...cursor authentications
STAT...consistent gets - exami
STAT...consistent changes
STAT...db block changes
STAT...parse time elapsed
STAT...parse time cpu
STAT...immediate (CURRENT) blo
latchchild cursor hash table
STAT...redo entries
STAT...CPU used by this sessio
STAT...CPU used when call star
latchenqueues
STAT...deferred (CURRENT) bloc
latchConsistent RBA
latchsession timer
latchactive checkpoint queue l
latchpost/wait queue
latchlgwr LWN SCN
latchmostly latch-free SCN
latchchannel operations parent
latchcache buffers lru chain
latchrow cache enqueue latch
latchrow cache objects
latchredo writing
latchsession allocation
latchundo global data
STAT...redo size
latchmessages
latchlibrary cache pin allocat
latchredo allocation
latchdml lock allocation
latchlibrary cache pin
latchenqueue hash chains
STAT...bytes received via SQL*
latchshared pool
latchlibrary cache
STAT...bytes sent via SQL*Net
latchcheckpoint queue latch
latchSQL memory manager workar
STAT...buffer is not pinned co
STAT...index scans kdiixs1
STAT...table scan blocks gotte
STAT...table scans (short tabl
STAT...table scan rows gotten
STAT...shared hash latch upgra
STAT...no work - consistent re
STAT...consistent gets
STAT...calls to get snapshot s
STAT...session logical reads
latchcache buffers chains
Run1 latches total versus runs -- difference and pct
Run1
125,072
PL/SQL 过程已成功完成。
SQL> spool off