简体   繁体   中英

How to find out which tables are most accessed or frequently used in Oracle 10g

I am facing trouble in getting the most frequently used tables in oracle 10g. I'm using Oracle 10g version 10.2.0.4.0 with EBS R12.1.3 Application on it.

Please help me in sorting out the most frequently used table in my DataBase.

If possible I would like to get the TableName, owner and how many times it was accessed between a time frame.

I need this for tuning purpose.

Please provide a query to get the same.

Thanks in advance !

I know 2 ways, one of them is to turn monitoring on all table and then use that statistic, or use v$segment_statistics to analyze block access statistic, something like this, shows you top 50 ordered by total value of access type tables, you shoul provide your target schema name < YOURSCHEMA > in the query.

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

If you require this for tuning an Oracle EBS environment, I suggest to start looking at it from the application or SQL rather than table and segment layer.

The AWR contains the most IO intensive queries for a particular date range as shown in DBA AWR SQL Performance Summary for example. Functions xxen_util.responsibility and xxen_util.apps_module used by this SQL can be downloaded 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM