Oracle DB 相關常用sql彙總6[知乎系列續]
####oracle AWR幾個重要的指標####
DB time
DB CPU(s)
Redo size (bytes)和Block changes
select s.metric_name, s.metric_unit, trim(to_char(max(s.average), '999G999G999G999G999D9')) max_value
from dba_hist_sysmetric_summary s
where s.metric_name in ('Redo Generated Per Sec', 'DB Block Changes Per Sec')
group by s.metric_name, s.metric_unit
記憶體讀
物理寫
select s.metric_name, s.metric_unit, trim(to_char(max(s.average), '999G999G999G999G999D9')) max_value
from dba_hist_sysmetric_summary s
where s.metric_name in ('Logical Reads Per Sec',
'Physical Reads Per Sec',
'Physical Read Bytes Per Sec',
'Physical Writes Per Sec',
'Physical Write Bytes Per Sec')
group by s.metric_name, s.metric_unit
order by 1
DB Time = DB CPU + Non-Idle Wait + Wait on CPU queue
DB Time也是前臺使用者耗費的資料庫時間
DB CPU是前臺使用者使用CPU的時間
Global Cache blocks received和Global Cache blocks served 常說的GC Buffer相關等待事件
select s.metric_name, s.metric_unit, trim(to_char(max(s.average), '999G999G999G999G999D9')) max_value
from dba_hist_sysmetric_summary s
where s.metric_name in ('User Calls Per Sec',
'Total Parse Count Per Sec',
'Hard Parse Count Per Sec',
'Logons Per Sec',
'Executions Per Sec',
'User Rollbacks Per Sec',
'User Transaction Per Sec')
group by s.metric_name, s.metric_unit
order by 1
AWR指標 top 10等待事件說明【Top 10 Foreground Events by Total Wait Time】
DB CPU和DB time的關係,我們可以按照所佔比例對資料庫健康狀況進行分級,如果DB CPU佔DB time超過90%,則資料庫非常健康,超過80%為健康
如果CPU佔DB time的30%-60%,那就表明資料庫已經是不健康的狀態,需要重點投入精力去改變健康狀況
如果CPU佔DB time的30%以下,那就表明資料庫已經是非常不健康的狀態,病入膏肓來形容一點都不誇張,不但要處理問題,而且要立即馬上快速的恢復。
查詢所有的等待事件,因為awr只包含了top10等待,所以用如下sql 查詢等待事件【dba_hist_system_event,配合快照表dba_hist_snapshot】
select ss.dbid "DB Id",
ss.snap_id - 1 "Begin Snap Id",
ss.snap_id "End Snap Id",
ss.instance_number "Inst num",
to_char(ss.begin_interval_time, 'YYYY-MM-DD HH24:MI:SS') "Begin Snap Time",
to_char(ss.end_interval_time, 'YYYY-MM-DD HH24:MI:SS') "End Snap Time",
se.event_name "Event",
(se.total_waits_fg - (select lse.total_waits_fg
from dba_hist_system_event lse
where lse.instance_number = se.instance_number
and lse.snap_id = se.snap_id - 1
and lse.dbid = se.dbid
and lse.event_name = se.event_name)) "Waits",
round((se.time_waited_micro_fg - (select lse.time_waited_micro_fg
from dba_hist_system_event lse
where lse.instance_number = se.instance_number
and lse.snap_id = se.snap_id - 1
and lse.dbid = se.dbid
and lse.event_name = se.event_name)) / 1000000,
1) "Total Wait Time (sec)",
se.wait_class "Wait Class"
from dba_hist_system_event se, dba_hist_snapshot ss
where ss.instance_number = se.instance_number
and ss.snap_id = se.snap_id
and ss.dbid = se.dbid
and ss.instance_number = 1
and ss.snap_id = 121743
and se.wait_class <> 'Idle'
order by ss.snap_id desc, ss.instance_number, 9 desc;
--每日歸檔量/每日歸檔次數
select logtime,count(*),round(sum(blocks*block_size)/1024/1024/1024) size_gb
from (select trunc(first_time,'dd') as logtime,a.blocks,a.block_size
from v$archived_log a
where a.dest_id=1
and a.first_time > trunc(sysdate-7))
group by logtime order by 1;
############Oracle 日誌挖掘 logminner#########
要提前設定utl_file_dir 目錄,與設定存放資料字典路徑要一致
1、execute dbms_logmnr_d.build ('dict.ora','/tmp',dbms_logmnr_d.store_in_flat_file);
execute dbms_logmnr.add_logfile(logfilename=>'+FRA/BARP_G/ARCHIVELOG/2017_09_25/thread_5_seq_30041.23632.955645029',options=>dbms_logmnr.new);
EXECUTE DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME => '/oracle/logs/log1.f',OPTIONS => DBMS_LOGMNR.NEW);
EXECUTE DBMS_LOGMNR.ADD_LOGFILE(LOGFILENAME => '/oracle/logs/log2.f',OPTIONS => DBMS_LOGMNR.ADDFILE);
2、 EXECUTE dbms_logmnr.start_logmnr(DictFileName => '/tmp/dict.ora');
3、 create table perfstat.logminer_5 nologging as select * from v$logmnr_contents;
4、 execute dbms_logmnr.end_logmnr;
函式說明:
函式
說明
dbms_logmnr.new
在資料字典中新增第一個需要分析的檔案
dbms_logmnr.addfile
在資料字典中新增其他需要分析的檔案
#######Oracle 壞塊處理恢復#######
Taking the advantage that the standby db and others standby dbs are
synchronized with the primary database :
1. Take an image copy of the datafile 98 from primary database or another
standby db where the file does not have corruption :
RMAN> backup as copy datafile 98 format '/temporary_location/data_ts_98.dbf';
Note: replace "'/temporary_location" with the complete location where you
can copy the file.
2. Copy the file '/temporary_location/data_ts_98.dbf' to the node where
is one instance of standby db.
3. In one of the instance of standby database, catalog the image copy of the
datafile :
RMAN> catalog datafilecopy ''/temporary_location_standby/data_ts_98.dbf';
4. Try to fix the corruption in the block reported corrupted :
RMAN> recover datafile 98 block 488820 ;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28211342/viewspace-2213236/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle DB 相關常用sql彙總7【手工繫結sql執行計劃】OracleSQL
- Oracle 效能相關常用指令碼(SQL)Oracle指令碼SQL
- 常用SQL技巧彙總SQL
- Oracle 統計資訊相關命令彙總Oracle
- ORACLE db相關nameOracle
- My SQL常用操作彙總SQL
- 常用SQL語句彙總SQL
- Oracle 常用方法彙總Oracle
- DB2常用命令彙總DB2
- 持續更新關於ORACLE X$檢視彙總Oracle
- oracle net相關問題的彙總和解決Oracle
- 表空間常用sql彙總SQL
- oracle 常用語句彙總Oracle
- oracle常用函式彙總Oracle函式
- kratos相關錯誤彙總
- ES6 常用知識彙總
- MySQL sys庫常用SQL彙總大全MySql
- MySql常用操作SQL語句彙總MySql
- python 系列文章彙總(持續更新…)Python
- SQL Performance Analyzer SPA常用指令碼彙總SQLORM指令碼
- 網路相關工具簡單彙總
- 資料庫常用的sql語句彙總資料庫SQL
- k8s 相關問題彙總K8S
- es6常用陣列操作及技巧彙總陣列
- 常用js彙總JS
- Oracle調優相關的各種命中率、使用率彙總Oracle
- Kafka 配置引數彙總及相關說明Kafka
- LR中winsock相關函式彙總函式
- Python常用6個技術網站彙總分享!Python網站
- 【SCRIPT】Oracle統計資訊相關SQLOracleSQL
- 常用函式彙總函式
- Oracle 最常用功能函式經典彙總Oracle函式
- 人臉識別相關開源專案彙總
- MySQL查詢最佳化方案彙總(索引相關)MySql索引
- DB2中如何實現Oracle的相關功能DB2Oracle
- sql相關SQL
- SQL的基本命令和幾個常用函式彙總SQL函式
- Oracle 表空間查詢相關sqlOracleSQL