`
itspace
  • 浏览: 962719 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

show_space&runstats

阅读更多
收录2个tkyte写的监控脚本,以备后用
1.show_space
引用
create or replace procedure show_space
( p_segname in varchar2,
  p_owner   in varchar2 default user,
  p_type    in varchar2 default 'TABLE',
  p_partition in varchar2 default NULL )
-- This procedure uses AUTHID CURRENT USER so it can query DBA_*
-- views using privileges from a ROLE and so it can be installed
-- once per database, instead of once per user who wanted to use it.
AUTHID CURRENT_USER
as
    l_free_blks                 number;
    l_total_blocks              number;
    l_total_bytes               number;
    l_unused_blocks             number;
    l_unused_bytes              number;
    l_LastUsedExtFileId         number;
    l_LastUsedExtBlockId        number;
    l_LAST_USED_BLOCK           number;
    l_segment_space_mgmt        varchar2(255);
    l_unformatted_blocks number;
    l_unformatted_bytes number;
    l_fs1_blocks number; l_fs1_bytes number;
    l_fs2_blocks number; l_fs2_bytes number;
    l_fs3_blocks number; l_fs3_bytes number;
    l_fs4_blocks number; l_fs4_bytes number;
    l_full_blocks number; l_full_bytes number;

    -- Inline procedure to print out numbers nicely formatted
    -- with a simple label.
    procedure p( p_label in varchar2, p_num in number )
    is
    begin
        dbms_output.put_line( rpad(p_label,40,'.') ||
                              to_char(p_num,'999,999,999,999') );
    end;
begin
   -- This query is executed dynamically in order to allow this procedure
   -- to be created by a user who has access to DBA_SEGMENTS/TABLESPACES
   -- via a role as is customary.
   -- NOTE: at runtime, the invoker MUST have access to these two
   -- views!
   -- This query determines if the object is an ASSM object or not.
   begin
      execute immediate
          'select ts.segment_space_management
             from dba_segments seg, dba_tablespaces ts
            where seg.segment_name      = :p_segname
              and (:p_partition is null or
                  seg.partition_name = :p_partition)
              and seg.owner = :p_owner
              and seg.tablespace_name = ts.tablespace_name'
             into l_segment_space_mgmt
            using p_segname, p_partition, p_partition, p_owner;
   exception
       when too_many_rows then
          dbms_output.put_line
          ( 'This must be a partitioned table, use p_partition => ');
          return;
   end;


   -- If the object is in an ASSM tablespace, we must use this API
   -- call to get space information; else we use the FREE_BLOCKS
   -- API for the user managed segments.
   if l_segment_space_mgmt = 'AUTO'
   then
     dbms_space.space_usage
     ( p_owner, p_segname, p_type, l_unformatted_blocks,
       l_unformatted_bytes, l_fs1_blocks, l_fs1_bytes,
       l_fs2_blocks, l_fs2_bytes, l_fs3_blocks, l_fs3_bytes,
       l_fs4_blocks, l_fs4_bytes, l_full_blocks, l_full_bytes, p_partition);

     p( 'Unformatted Blocks ', l_unformatted_blocks );
     p( 'FS1 Blocks (0-25)  ', l_fs1_blocks );
     p( 'FS2 Blocks (25-50) ', l_fs2_blocks );
     p( 'FS3 Blocks (50-75) ', l_fs3_blocks );
     p( 'FS4 Blocks (75-100)', l_fs4_blocks );
     p( 'Full Blocks        ', l_full_blocks );
  else
     dbms_space.free_blocks(
       segment_owner     => p_owner,
       segment_name      => p_segname,
       segment_type      => p_type,
       freelist_group_id => 0,
       free_blks         => l_free_blks);

     p( 'Free Blocks', l_free_blks );
  end if;

  -- And then the unused space API call to get the rest of the
  -- information.
  dbms_space.unused_space
  ( segment_owner     => p_owner,
    segment_name      => p_segname,
    segment_type      => p_type,
    partition_name    => p_partition,
    total_blocks      => l_total_blocks,
    total_bytes       => l_total_bytes,
    unused_blocks     => l_unused_blocks,
    unused_bytes      => l_unused_bytes,
    LAST_USED_EXTENT_FILE_ID => l_LastUsedExtFileId,
    LAST_USED_EXTENT_BLOCK_ID => l_LastUsedExtBlockId,
    LAST_USED_BLOCK => l_LAST_USED_BLOCK );

    p( 'Total Blocks', l_total_blocks );
    p( 'Total Bytes', l_total_bytes );
    p( 'Total MBytes', trunc(l_total_bytes/1024/1024) );
    p( 'Unused Blocks', l_unused_blocks );
    p( 'Unused Bytes', l_unused_bytes );
    p( 'Last Used Ext FileId', l_LastUsedExtFileId );
    p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );
    p( 'Last Used Block', l_LAST_USED_BLOCK );
end;
/


2.runstats
引用
The table we need is very simple:

create global temporary table run_stats
( runid varchar2(15),
  name varchar2(80),
  value int )
on commit preserve rows;

then you can create this view:

create or replace view stats
as select 'STAT...' || a.name name, b.value
      from v$statname a, v$mystat b
     where a.statistic# = b.statistic#
    union all
    select 'LATCH.' || name,  gets
      from v$latch
union all
select 'STAT...Elapsed Time', hsecs from v$timer;

Now the test harness package itself is very simple. Here it is:

create or replace package runstats_pkg
as
    procedure rs_start;
    procedure rs_middle;
    procedure rs_stop( p_difference_threshold in number default 0 );
end;
/

create or replace package body runstats_pkg
as

g_start number;
g_run1  number;
g_run2  number;

procedure rs_start
is
begin
    delete from run_stats;

    insert into run_stats
    select 'before', stats.* from stats;
       
    g_start := dbms_utility.get_time;
end;

procedure rs_middle
is
begin
    g_run1 := (dbms_utility.get_time-g_start);

    insert into run_stats
    select 'after 1', stats.* from stats;
    g_start := dbms_utility.get_time;

end;

procedure rs_stop(p_difference_threshold in number default 0)
is
begin
    g_run2 := (dbms_utility.get_time-g_start);

    dbms_output.put_line
    ( 'Run1 ran in ' || g_run1 || ' hsecs' );
    dbms_output.put_line
    ( 'Run2 ran in ' || g_run2 || ' hsecs' );
    dbms_output.put_line
    ( 'run 1 ran in ' || round(g_run1/g_run2*100,2) ||
      '% of the time' );
    dbms_output.put_line( chr(9) );

    insert into run_stats
    select 'after 2', stats.* from stats;

    dbms_output.put_line
    ( rpad( 'Name', 30 ) || lpad( 'Run1', 12 ) ||
      lpad( 'Run2', 12 ) || lpad( 'Diff', 12 ) );

    for x in
    ( select rpad( a.name, 30 ) ||
             to_char( b.value-a.value, '999,999,999' ) ||
             to_char( c.value-b.value, '999,999,999' ) ||
             to_char( ( (c.value-b.value)-(b.value-a.value)), '999,999,999' ) data
        from run_stats a, run_stats b, run_stats c
       where a.name = b.name
         and b.name = c.name
         and a.runid = 'before'
         and b.runid = 'after 1'
         and c.runid = 'after 2'
         -- and (c.value-a.value) > 0
         and abs( (c.value-b.value) - (b.value-a.value) )
               > p_difference_threshold
       order by abs( (c.value-b.value)-(b.value-a.value))
    ) loop
        dbms_output.put_line( x.data );
    end loop;

    dbms_output.put_line( chr(9) );
    dbms_output.put_line
    ( 'Run1 latches total versus runs -- difference and pct' );
    dbms_output.put_line
    ( lpad( 'Run1', 12 ) || lpad( 'Run2', 12 ) ||
      lpad( 'Diff', 12 ) || lpad( 'Pct', 10 ) );

    for x in
    ( select to_char( run1, '999,999,999' ) ||
             to_char( run2, '999,999,999' ) ||
             to_char( diff, '999,999,999' ) ||
             to_char( round( run1/run2*100,2 ), '99,999.99' ) || '%' data
        from ( select sum(b.value-a.value) run1, sum(c.value-b.value) run2,
                      sum( (c.value-b.value)-(b.value-a.value)) diff
                 from run_stats a, run_stats b, run_stats c
                where a.name = b.name
                  and b.name = c.name
                  and a.runid = 'before'
                  and b.runid = 'after 1'
                  and c.runid = 'after 2'
                  and a.name like 'LATCH%'
                )
    ) loop
        dbms_output.put_line( x.data );
    end loop;
end;

end;
/

/*
exec runStats_pkg.rs_start;
exec runStats_pkg.rs_middle;
exec runStats_pkg.rs_stop;
*/



分享到:
评论

相关推荐

    runstats.sql

    tom的runstats脚本,在oracle 11g测试没有问题,可以正常实现。

    Python库 | runstats-2.0.0-cp37-cp37m-win_amd64.whl

    资源分类:Python库 所属语言:Python 资源全名:runstats-2.0.0-cp37-cp37m-win_amd64.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    DB2如何评估索引碎片是否是缓慢的RUNSTATS根

    索引碎片可能由正常的数据库活动导致,比如 INSERT 和 UPDATE。当索引变得高度碎片化时,会对 RUNSTATS 性能 产生重大影响。您可学习识别何时出现了这种情形,并采取更正措施。

    python-runstats:一次计算统计量和回归量的Python模块

    RunStats:一站式计算统计和回归 是Apache2许可的Python模块,用于在线统计和在线回归。 统计信息和回归摘要均通过一次计算。 以前的值不会记录在摘要中。 长时间运行的系统通常会生成汇总性能的数字。 可能是响应...

    DB2调优技巧

    DB2调优技巧

    DB2基本命令 实例管理和常用dml

    db2 runstats on table ydd with distribution and indexes all 13.导出表数据 db2 export to c:\dftz.txt of del select * from dftz db2 export to c:\dftz.ixf of ixf select * from dftz 14.导入表数据 ...

    关于数据库DB2 常用命令

    RUNSTATS -> REORGCHK -> REORG -> RUNSTATS -> BIND或REBIND 0 执行下面命令前要先连接数据库 1 RUNSTATS 由于在第二步中REORGCHK时可以对指定的表进行RUNSTATS操作(在REORGCHK时指定UPDATE STATISTICS),...

    mysql 调优总结

    为什么要优化? 随着数据量的增大, mysql服务性能差从而直接影响用户体验。 查询时结果显示的很慢等。 哪些方面可以优化? 1、优化硬件、操作系统 2、优化MySQL服务器 3、优化DB设计 ...#指定MySQ

    DB2 日常维护指南,第 3 部分

    DB2 日常维护指南,第 3 部分 摘自IBM官网 检查是否需要运行 runstats 和 reorg

    DB2性能调优

    DB2性能调优 The DB2 Optimizer SQL Coding Strategies and Guidelines DB2 Catalog Filter Factors for Predicates Runstats and Reorg Utilities

    DB2最新维护手册,从豆丁买来的。

    13、 对表和索引进行RUNSTATS 14 14、 检查表是否需要重组 14 15、 对需要重组的表进行重组 15 三、 DB2日常维护月操作 15 1、 查看DB2日志 15 2、 检查备份和日志是否都保存好了 15 四、 DB2日常维护季度操作 15 1...

    深度分析:DB2性能调优

    DB2性能调优 内容提纲 1.The DB2 Optimizer 2.SQL Coding Strategies and Guidelines 3.DB2 Catalog 4.Filter Factors for Predicates 5.Runstats and Reorg Utilities

    uid-decoding

    UID解码 基于SGNMT的解码库: : ...要编译统计信息类,请导航至runstats子模块: cd runstats python setup.py install 入门 我们建议从fairseq提供的预训练模型开始。 从其NMT示例中下载任何模型,解压缩并将模型检

    matlab弹出对话框代码-GenericMemoryTask:Mednick实验室中用于实验的内存任务脚本

    计算统计信息的代码(例如runStats_WPA) 一个设置文件,用于控制所有任务参数(时间,运行哪些列表,要运行多少图像,要显示的文本等) 特征: 弹出输入对话框以输入主题ID,会话ID或其他参数 一个脚本来检查数据...

    DB2 SQL性能调优秘笈

    第6章介绍了Runstats,用来得到一些统计信息;第7章讲解了DB2性能优化的“15步调优法”,被誉为DB2性能调优领域的无价之宝,适用于各种情况下的性能调优问题。《DB2 SQL性能调优秘笈》最后还有2个附录,分别介绍了...

    DB2维护手册.pdf

    13、 对表和索引进行runstats 6 14、 检查表是否需要重组 6 15、 对需要重组的表进行重组 7 二、 DB2日常维护月操作 7 1、 查看DB2日志 7 2、 检查备份和日志是否都保存好了 7 三、 DB2日常维护季度操作 7 1、 通过...

    db2-技术经验总结

    1.74. 给表增加索引的时候,可以增加collect detailed statistics参数来避免对表索引重新runstats(原) 100 1.75. DB2 LOAD命令所提供的选项及注册表变量使用 100 1.76. 在windows上配置数据源(原) 109 1.77. DB2 ...

    IBM DB2经典视频教程

    第6周 DB2性能优化:运维工具优化,包括Runstats、Reorg、Export、Import、Load、Backup/Restore等。 第7周 DB2性能优化:锁机制深入解析,包括并发、隔离级、锁概念、DB2与Oracle锁机制对比等。 第8周 DB2性能优化...

    simulate-cribbage-games:模拟和分析两个玩家之间的纸牌游戏

    )测试检查类型错误-应该只找到与runstats模块有关的类型错误,其中没有类型提示: mypy simulateCribbageGames.py使用模拟从交易到手数计算的一只手: python simulateCribbageGames.py 有关其他模拟选项的帮助: ...

    miseq-16S-pipeline:HPC管线,用于在Illumina MiSeq上生成的重叠V4 16S rRNA读数

    BioPython , pandas和runstats (只需pip install -r requirements.txt )。 Pandaseq (来自GitHub上的ref )( brew install pandaseq --HEAD将在您使用Mac并安装了homebrew + homebrew-science的情况下工作) ...

Global site tag (gtag.js) - Google Analytics