【问题标题】:How to find out which tables are most accessed or frequently used in Oracle 10g如何找出 Oracle 10g 中访问次数最多或使用频率最高的表
【发布时间】:2017-09-09 02:35:37
【问题描述】:

我在获取 oracle 10g 中最常用的表时遇到了麻烦。 我正在使用带有 EBS R12.1.3 应用程序的 Oracle 10g 版本 10.2.0.4.0。

请帮我整理一下我的数据库中最常用的表。

如果可能,我想获取 TableName、所有者以及在一个时间范围内访问它的次数。

我需要这个来调优。

请提供查询以获得相同的结果。

提前致谢!

【问题讨论】:

  • 您确定要根据访问表的次数进行调整吗?如果一张表被访问一次但需要几个小时的处理时间,这难道不比一张表在一秒钟内被访问一千次更重要吗?在 Oracle 中,根据等待时间进行调整通常更有帮助。很容易成为强迫性调优障碍的牺牲品,并浪费时间优化不相关的查询。您希望专注于最重要的指标,通常是做某事所花费的时间。

标签: database oracle performance oracle10g database-tuning


【解决方案1】:

我知道 2 种方法,其中一种是对所有表进行监控,然后使用该统计信息,或者使用 v$segment_statistics 分析块访问统计信息,类似这样,显示按访问类型总值排序的前 50表,您应该在查询中提供您的目标模式名称< YOURSCHEMA >

select *
  from (select rownum RN, T.*
           from (select stat.OBJECT_NAME, stat.STATISTIC_NAME, stat.VALUE AcsValue,
                         sum(value) over(partition by stat.OBJECT_NAME) Total
                    from v$segment_statistics stat
                   where owner = < YOURSCHEMA >
                     and stat.OBJECT_TYPE = 'TABLE'
                     and stat.STATISTIC_NAME in
                         ('logical reads', 'pptimized physical reads',
                          'physical read requests', 'physical reads',
                          'physical reads direct', 'physical write requests',
                          'physical writes', 'physical writes direct')
                   order by sum(value) over(partition by stat.OBJECT_NAME) desc) T) TOrd
 where TOrd.RN < 50

【讨论】:

    【解决方案2】:

    如果您需要它来调优 Oracle EBS 环境,我建议您从应用程序或 SQL 开始,而不是表和段层。

    AWR 包含特定日期范围内 IO 最密集的查询,例如 DBA AWR SQL Performance Summary 中所示。该SQL用到的函数xxen_util.responsibility和xxen_util.apps_module可以在here下载。

    select
    decode(:order_by,
    'elapsed time',x.elapsed_time/sum(x.elapsed_time) over ()*100,
    'IO',x.buffer_io/sum(x.buffer_io) over ()*100,
    'executions',x.executions/sum(x.executions) over ()*100
    ) percentage,
    xxen_util.responsibility(x.action) responsibility,
    xxen_util.apps_module(x.module) apps_module,
    x.module,
    x.program,
    x.program_line#,
    x.sql_id,
    x.plan_hash_value,
    (select dhst.sql_text from dba_hist_sqltext dhst where x.dbid=dhst.dbid and x.sql_id=dhst.sql_id) sql_text,
    x.executions,
    x.elapsed_time,
    xxen_util.time(x.elapsed_time) time,
    x.user_io_wait_time,
    x.cpu_time,
    x.plsql_exec_time,
    x.concurrency_wait_time,
    x.application_wait_time,
    x.elapsed_time/decode(x.executions,0,null,x.executions) time_exec,
    x.buffer_io,
    x.disk_io,
    x.buffer_io/decode(x.executions,0,null,x.executions) io_exec,
    x.rows_processed/decode(x.executions,0,null,x.executions) rows_exec,
    x.buffer_io/decode(x.rows_processed,0,null,x.rows_processed) io_row,
    x.buffer_io/decode(x.elapsed_time,0,null,x.elapsed_time) io_sec,
    case when x.executions>100 then x.buffer_io/(decode(x.last_load_time,x.first_load_time,to_date(null),x.last_load_time)-x.first_load_time)/24/3600 end io_sec_avg,
    (x.buffer_io-x.disk_io)/xxen_util.zero_to_null(x.cpu_time) buffer_rate,
    x.disk_io/xxen_util.zero_to_null(x.user_io_wait_time) disk_rate,
    100*x.disk_io/xxen_util.zero_to_null(x.buffer_io) disk_percentage,
    case when x.executions>100 then x.executions/(decode(x.last_load_time,x.first_load_time,to_date(null),x.last_load_time)-x.first_load_time)/24 end execs_per_hour,
    case when x.executions>100 then 100*x.elapsed_time/(decode(x.last_load_time,x.first_load_time,to_date(null),x.last_load_time)-x.first_load_time)/24/3600 end time_percentage,
    x.is_bind_sensitive,
    x.is_bind_aware,
    x.parsing_schema_name,
    x.parse_calls,
    x.first_load_time,
    x.last_load_time,
    x.command_type,
    x.action
    from
    (
    select /*+ cardinality(dhs 100) */ distinct
    case when :aggregate_level like '% per day' then dhs.date_ end date_,
    case when :aggregate_level like 'SQL%' then max(dhss.module) over (partition by dhss.sql_id, dhss.plan_hash_value) else dhss.module end module,
    case when :aggregate_level like 'SQL%' then max(dhss.action) over (partition by dhss.sql_id, dhss.plan_hash_value) else dhss.action end action,
    sum(dhss.elapsed_time_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 elapsed_time,
    sum(dhss.iowait_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 user_io_wait_time,
    sum(dhss.cpu_time_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 cpu_time,
    sum(dhss.plsexec_time_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 plsql_exec_time,
    sum(dhss.ccwait_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 concurrency_wait_time,
    sum(dhss.apwait_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 application_wait_time,
    vp.value*sum(dhss.buffer_gets_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 buffer_io,
    sum(dhss.physical_read_bytes_delta) over (partition by dhss.sql_id, dhss.plan_hash_value)/1000000 disk_io,
    sum(dhss.executions_delta) over (partition by dhss.sql_id, dhss.plan_hash_value) executions,
    sum(dhss.rows_processed_delta) over (partition by dhss.sql_id, dhss.plan_hash_value) rows_processed,
    min(dhss.parsing_schema_name) over (partition by dhss.sql_id, dhss.plan_hash_value) parsing_schema_name,
    sum(dhss.parse_calls_delta) over (partition by dhss.sql_id, dhss.plan_hash_value) parse_calls,
    min(dhs.begin_interval_time_) over (partition by dhss.sql_id, dhss.plan_hash_value) first_load_time,
    max(dhs.end_interval_time_) over (partition by dhss.sql_id, dhss.plan_hash_value) last_load_time,
    case when :aggregate_level like 'SQL%' then dhss.sql_id end sql_id,
    case when :aggregate_level like 'SQL%' then dhss.plan_hash_value end plan_hash_value,
    case when :aggregate_level like 'SQL%' then decode(dhst.command_type,1,'create table',2,'insert',3,'select',6,'update',7,'delete',9,'create index',11,'alter index',26,'lock table',42,'alter session',44,'commit',45,'rollback',46,'savepoint',47,'pl/sql block',48,'set transaction',50,'explain',62,'analyze table',90,'set constraints',170,'call',189,'merge','other') end command_type,
    case when :aggregate_level like 'SQL%' then gsa.is_bind_sensitive end is_bind_sensitive,
    case when :aggregate_level like 'SQL%' then gsa.is_bind_aware end is_bind_aware,
    case when :aggregate_level like 'SQL%' then gsa.object_name end program,
    case when :aggregate_level like 'SQL%' then gsa.program_line# end program_line#,
    dhs.dbid
    from
    (
    select trunc(dhs.begin_interval_time) date_,
    cast(dhs.begin_interval_time as date) begin_interval_time_,
    cast(dhs.end_interval_time as date) end_interval_time_,
    dhs.*
    from
    dba_hist_snapshot dhs
    ) dhs,
    dba_hist_sqlstat dhss,
    dba_hist_sqltext dhst,
    (
    select
    gsa.sql_id,
    gsa.plan_hash_value,
    gsa.is_bind_sensitive,
    gsa.is_bind_aware,
    do.object_name,
    case when gsa.program_line#>0 then gsa.program_line# end program_line#
    from
    gv$sqlarea gsa,
    dba_objects do
    where
    2=2 and
    'Y'='Y' and
    gsa.program_id=do.object_id(+)
    ) gsa,
    (select vp.value from v$parameter vp where vp.name like 'db_block_size') vp
    where
    dhs.begin_interval_time>=:date_from and
    dhst.command_type not in (47) and
    1=1 and
    dhs.dbid=(select vd.dbid from v$database vd) and
    dhs.dbid=dhss.dbid and
    dhs.instance_number=dhss.instance_number and
    dhs.snap_id=dhss.snap_id and
    dhss.dbid=dhst.dbid and
    dhss.sql_id=dhst.sql_id and
    dhss.sql_id=gsa.sql_id(+) and
    dhss.plan_hash_value=gsa.plan_hash_value(+)
    ) x
    order by
    case when :aggregate_level in ('Module per day','SQL per day') then x.date_ end desc,
    decode(:order_by,'elapsed time',x.elapsed_time,'IO',x.buffer_io,'executions',x.executions) desc
    
    -- binds --
    :aggregate_level = SQL
    :order_by = IO
    

    【讨论】:

      猜你喜欢
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-09
      相关资源
      最近更新 更多