zoukankan      html  css  js  c++  java
  • oracle database 12cr2 使用 dbms_stat 采集统计信息

    dbms_stat 是oracle database 采集统计信息的集成工具。非常方便和高效。

    备份

    创建stat_table

    begin
        dbms_stats.create_stat_table(
            ownname => 'drp',
            stattab => 'stat_table'
        ) ; 
    end;

    导出整个scheme的统计信息

    begin
       dbms_stats.export_schema_stats(
            ownname => 'drp',
            stattab => 'stat_table'
       ) ; 
    end;   

    分析

    begin
       --固定表的统计信息
       sys.dbms_stats.gather_fixed_objects_stats;
       --数据字典的统计信息
       sys.dbms_stats.gather_dictionary_stats;
       --instance的统计信息
       sys.dbms_stats.gather_system_stats();
    end; 

    抽样分析drp用户对象

    BEGIN
       sys.dbms_stats.gather_schema_stats(
           ownname=> 'drp' ,
           estimate_percent=> 50 , 
           cascade=> TRUE,
           --method_opt=>'for all columns size 1 '
           --method_opt=>'for all columns size repeat ',
           method_opt=>'for all indexed columns size skewonly ',
           degree=>8
       );
    END ;

    抽样分析drp.order表

    BEGIN
        dbms_stats.gather_table_stats(
            ownname=> 'drp' ,
            tabname=> 'order',
            estimate_percent=> 50 , 
            cascade=> TRUE,
            --method_opt=>'for all columns size 1 ',
            --method_opt=>'for all columns size repeat ',
            method_opt=>'for all indexed columns size skewonly ',
            no_invalidate=>FALSE,
            granularity=>'AUTO',
            degree=>8
        );
    END ;

    抽样分析drp.order表的idx_order_x1索引

    BEGIN
        sys.dbms_stats.gather_index_stats(
            ownname=> 'drp' ,
            indname=>'idx_order_x1',
            estimate_percent=> 100 
        );
    END ; 

    method_opt选项
    for table–只统计表 
    for all indexed columns–只统计有索引的表列
    for all indexes–只分析统计相关索引
    for all columns

    在method_opt子句中,还有一些重要的新选项,包括skewonly,repeat和auto:
    method_opt=>’for all columns size 1’
    method_opt=>’for all columns size skewonly’
    method_opt=>’for all columns size repeat’
    method_opt=>’for all columns size auto’

    删除

    重新采集后发现效果不好的,可以删除统计信息

    删除整个schema的统计信息

    begin
        dbms_stats.delete_schema_stats(
           ownname => 'drp'
        ) ;
    end; 

    删除表的统计信息

    begin
        dbms_stats.delete_table_stats(
           ownname => 'drp',
           tabname => 'order'
        ) ;
    end;    

    导入

    导入表的统计信息

    begin
        dbms_stats.import_table_stats(
           ownname => 'drp',
           tabname => 'order',
           stattab => 'stat_table'
        ) ; 
    end;

    导入整个schema的统计信息

    begin
        dbms_stats.import_schema_stats(
           ownname => 'drp',
           stattab => 'stat_table'
        );
    end;
  • 相关阅读:
    运行ConnectionDemo时遇到的问题及解决方案
    xampp启动MySQL出现Error: MySQL shutdown unexpectedly.
    20175227张雪莹 2018-2019-2 《Java程序设计》第八周学习总结
    KMS
    MAC 添加共享,脚本执行
    zabbix企业应用之windows系统安装omsa硬件监控
    SCCM大致安装过程,参考前辈教程完成部署
    MAC加域重复跳出---"talagent"想使用“本地项目” 的钥匙串
    CentOS Linux解决 Device eth0 does not seem to be present
    zabbix3.0.4 部署History
  • 原文地址:https://www.cnblogs.com/ctypyb2002/p/9793016.html
Copyright © 2011-2022 走看看