oracle資料庫SQL相關指標統計分析

2021-07-25 00:05:44 字數 3579 閱讀 1189



---查詢sql當前的指標:

select

a.hash_value, a.sql_text,

a.plan_hash_value,

round(a.buffer_gets/a.executions) bg_per_exec,

round(a.cpu_time/1000/a.executions) cpu_per_exec,

round(a.elapsed_time/1000/a.executions) time_per_exec,     

round(a.rows_processed/a.executions) rows_per_exec,

a.executions,

a.buffer_gets,

a.disk_reads,

a.cpu_time,

a.elapsed_time,

a.rows_processed

from v$sql a

where hash_value=377282797

and cpu_time<>0

and buffer_gets<>0

and rows_processed<>0

order by sql_text

/--查詢sql的歷史執行次數變化:

select b.begin_interval_time, a.sql_id,a.executions_delta,a.executions_delta/(15*60)

from dba_hist_sqlstat a, dba_hist_snapshot b where

a.sql_id in  ('0js9jz3qx087j')

and b.begin_interval_time> to_date('2014-03-31 13:00:00','yyyy-mm-dd hh24:mi:ss')

and b.begin_interval_time

---sql歷史上邏輯讀、物理讀、執行時間等的變化 (毫秒)

select b.begin_interval_time, a.sql_id,a.plan_hash_value,a.executions_delta,

round((a.buffer_gets_delta) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) bg_per_exec,

round((a.disk_reads_delta) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) diskr_per_exec,

round((a.cpu_time_delta/1000) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) ctime_ms_per_exec,

round((a.elapsed_time_delta/1000) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) etime_ms_per_exec,

round((a.apwait_delta/1000) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) apwait_delta_ms_per_exec,

round((a.ccwait_delta/1000) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) ccwait_delta_ms_per_exec,

round((a.rows_processed_total) /decode(nvl(a.executions_delta, 0),0,1, a.executions_delta),3) row_process_per_exec

from dba_hist_sqlstat a, dba_hist_snapshot b

where a.sql_id = 'atd4sn0445c66'

and b.begin_interval_time> to_date('2014-12-04 09:00:00','yyyy-mm-dd hh24:mi:ss')

and  b.begin_interval_timeselect b.begin_interval_time, a.sql_id,a.plan_hash_value,a.executions_delta,

round(a.buffer_gets_delta/a.executions_delta,3) bg_per_exec,

round(a.disk_reads_delta/a.executions_delta,3) diskr_per_exec,

round(a.cpu_time_delta/1000/a.executions_delta,3) ctime_ms_per_exec,

round(a.elapsed_time_delta/1000/a.executions_delta,3) etime_ms_per_exec,

round(a.apwait_delta/1000/a.executions_delta,3) apwait_ms_delta_per_exec,

round(a.ccwait_delta/1000/a.executions_delta,3) ccwait_ms_delta_per_exec,

round(a.rows_processed_total/a.executions_delta,3) row_process_per_exec

from dba_hist_sqlstat a, dba_hist_snapshot b

where a.sql_id = 'fvxkpft53fmqj'

and b.begin_interval_time> to_date('2014-12-26 09:00:00','yyyy-mm-dd hh24:mi:ss')

and  b.begin_interval_time

----查詢一段時間內每個snapshot 間隔內的top sql:

select snap_id,begin_interval_time,sql_id,executions_delta,round(cpu_time_ms/executions_delta) cpu_time_per_exec_ms,ranking from

(select * from

(select a.snap_id,b.begin_interval_time,a.sql_id,a.executions_delta,round(a.cpu_time_delta/1000) cpu_time_ms,

rank() over (partition by a.snap_id order by a.cpu_time_delta desc) ranking

from dba_hist_sqlstat a, dba_hist_snapshot b

where a.snap_id=b.snap_id

and b.begin_interval_time> to_date('2015-01-04 09:30:00','yyyy-mm-dd hh24:mi:ss')

and  b.begin_interval_time

SQL資料庫相關

資料庫相關知識點 sql,對錶的理解,對錶的主鍵,外來鍵的理解,檢視,為什麼要有檢視,檢視有什麼功能,檢視與表有什麼區別 主鍵是唯一標識的一條記錄,不能重複,不能為空 表的外來鍵是另乙個表的主鍵,可以重複,可以為空 索引,字段沒有重複值,可以有空值,可以有乙個或者多個唯一索引 檢視是乙個或者多個表按...

oracle資料庫相關操作

查詢兩個欄位的重複資料 select from a1 a where a.rowid select max b.rowid from a1 b where a.cldbh b.cldbh and a.sjsj b.sjsj rowid是資料的詳細位址,通過rowid,oracle可以快速的定位某行具...

oracle資料庫相關操作

最近公司乙個專案要遷移到oracle資料庫,發現oracle與mysql操作有很多不同,記錄一下 獲取系統時間 mysql newdate sqlserver sysdatetime oracle sysdate ora 00911 無效字元 在mybatis中寫oracle sql,末尾不要加分號...