ITPub博客

首页 > 数据库 > Oracle > 【TUNE_ORACLE】定制化收集统计信息SQL参考

【TUNE_ORACLE】定制化收集统计信息SQL参考

原创 Oracle 作者:Attack_on_Jager 时间:2021-08-02 09:59:00 0 删除 编辑

实验环境

搭建平台:VMware Workstation

OS:RHEL 6.10

Grid&DB:Oracle 11.2.0.4


SQL参考

declare

  cursor stale_table is

    select owner,

           segment_name,

           case

             when segment_size < 1 then

              100

             when segment_size >= 1 and segment_size <= 5 then

              50

             when segment_size > 5 then  --超过5G的大表收集比例一般不超过30%

              30

           end as percent,

           4 as degree

      from (select owner,

                   segment_name,

                   sum(bytes / 1024 / 1024 / 1024) segment_size

              from dba_segments

             where owner = 'TEST'

               and segment_name in

                   (select table_name

                      from dba_tab_statistics

                     where (last_analyzed is null or stale_stats = 'YES')

                       and owner = 'TEST')

             group by owner, segment_name);

begin

  dbms_stats.flush_database_monitoring_info;

  for stale in stale_table loop

    dbms_stats.gather_table_stats(ownname          => stale.owner,

                                  tabname          => stale.segment_name,

                                  estimate_percent => stale.percent,

                                  method_opt       => 'for all columns size repeat',  --根据实际情况选择该参数

                                  degree           => stale.degree,

                                  cascade          => true);

  end loop;

end;

/

 

单独拆分成一条关键语句:

SQL> exec dbms_stats.gather_table_stats(ownname  => 'test',tabname  =>  'tab',estimate_percent  =>  50,method_opt  =>  'for all columns size auto',no_invalidate => false,degree  =>  6,cascade  => true);


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69992972/viewspace-2784605/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
在某银行任职DBA,拥有多年数据库运维经验,擅长Oracle,MySQL。尤其擅长Oracle的SQL优化,数据库性能调优,数据库备份、恢复与迁移。拥有的认证:OCM 12c,OCM 11g,MySQL OCP,RHCE,阿里云ACP,巨杉SCDP,软考系统集成工程师认证,Oracle Iaas OCA,OBCA,TDSQL认证,TBase认证

注册时间:2021-01-11

  • 博文量
    142
  • 访问量
    482837