SQL獲取AWR資訊

2021-08-03 11:58:58 字數 3598 閱讀 5140

----快照排序

select snap_id,dbid,end_time from (

select snap_id,dbid,to_char(end_interval_time,'yyyy-mm-dd hh24:mi:ss') end_time from dba_hist_snapshot

order by end_interval_time desc)

where rownum<100;

------plsql取awr報告

select * from table(dbms_workload_repository.awr_report_html('203185647',1,175129,175130));

----建立快照

exec dbms_workload_repository.create_snapshot;

-----某個sql在時間範圍內的情況

select a.snap_id,c.begin_interval_time,c.end_interval_time,a.elapsed_time_delta/a.executions_delta/1000000 "s",a.sql_id,b.sql_text,a.buffer_gets_delta/a.executions_delta "buffer_gets/次",a.disk_reads_delta/a.executions_delta "disk_read/次" from dba_hist_sqlstat a, dba_hist_sqltext b,dba_hist_snapshot c

where a.sql_id=b.sql_id 

and a.snap_id=c.snap_id

and a.sql_id='18ahw8aawvkbr'

and a.snap_id between 182723 and 184126

and a.executions_delta >0;

------

select s.instance_number,s.snap_id, to_char(sn.end_interval_time,'yyyymmdd hh24:mi:ss'),s.plan_hash_value, s.executions_delta,

round(s.elapsed_time_delta/s.executions_delta) ,

round(s.disk_reads_delta/s.executions_delta) ,

round(s.buffer_gets_delta/s.executions_delta) ,

round(s.cpu_time_delta/s.executions_delta),

round(s.ccwait_delta/s.executions_delta),

round(s.iowait_delta/s.executions_delta),

round(s.apwait_delta/s.executions_delta)

from dba_hist_snapshot sn, dba_hist_sqlstat s

where s.snap_id = sn.snap_id and s.sql_id='dd4rakddcp6tp'

and s.instance_number=sn.instance_number

and s.executions_delta>0

order by sn.end_interval_time desc;

select s.instance_number,s.snap_id, to_char(sn.end_interval_time,'yyyymmdd hh24:mi:ss'),s.plan_hash_value, s.executions_delta,

round(s.elapsed_time_delta) ,

round(s.disk_reads_delta) ,

round(s.buffer_gets_delta) ,

round(s.cpu_time_delta),

round(s.ccwait_delta),

round(s.iowait_delta),

round(s.apwait_delta)

from dba_hist_snapshot sn, dba_hist_sqlstat s

where s.snap_id = sn.snap_id and s.sql_id='6m8yzqna87n8t'

and s.instance_number=sn.instance_number

order by sn.end_interval_time desc;

select s.instance_number,s.snap_id, to_char(sn.end_interval_time,'yyyymmdd hh24:mi:ss'),s.plan_hash_value, s.executions_delta,

round(s.elapsed_time_delta/s.executions_delta) elspsed_time ,

round(s.disk_reads_delta/s.executions_delta) disk_reads,

round(s.buffer_gets_delta/s.executions_delta) buffer_gets ,

round(s.cpu_time_delta/s.executions_delta) cpu_time,

round(s.ccwait_delta/s.executions_delta) ccwait_delta,

round(s.iowait_delta/s.executions_delta) iowait_delta,

round(s.apwait_delta/s.executions_delta) apwait_delta

from dba_hist_snapshot sn, dba_hist_sqlstat s

where s.snap_id = sn.snap_id and s.sql_id='1q6wcxm90w0tr'

and s.instance_number=sn.instance_number

and s.executions_delta>0

order by sn.end_interval_time desc;

----索引聚因子

在上述sql語句的輸出結果中,如果dba_indexes.clustering_factor接近表中塊的數量,

那麼表中大多數行是排序的。這是期望的。

然而,如果clustering factor接近表中行的數量,

它意味著表中的行是隨機排列,這種情況對於同樣葉塊中的索引塊來說,

指向同樣的資料塊中的行是不可能的,因此它會導致更多的i/o來完成操作。

你可以採取rebuilding表來改善索引clustering factor,為了行根據索引鍵來排序,其後重建索引。

select id.index_name,tb.table_name,id.clustering_factor,tb.num_rows,tb.blocks

from dba_indexes id,dba_tables tb

where id.table_name=tb.table_name 

and tb.table_name='***x'and tb.owner='&2'

oracle如何獲取awr報告

oracle database 10g 提供了乙個顯著改進的工具 自動工作負載資訊庫 awr awr 和資料庫一起安裝。資料庫裝好後,快照由乙個稱為 mmon 的新的後台程序及其從程序自動地每小時採集一次 snap 要檢視當前的設定,您可以使用下面的語句 select snap interval,r...

SQL 獲取表結構資訊

select 表名 d.name,表說明 isnull f.value,字段序號 a.colorder,欄位名 a.name,標識 case when columnproperty a.id,a.name,isidentity 1 then else end,主鍵 case when exists ...

批量獲取AWR報告的指令碼

在實際的使用過程中發現,當撈取較長時間的awr報告時,例如過去24小時的awr報告 通常以1小時或者半小時為單位獲取 則需要執行24次獲取awr報告的操作 獲取awr報告的相關操作可以參見 於是針對此批量獲取awr報告有編寫如下指令碼 首先以sysdba的方式進入資料庫 su oracle sqlp...