SCN HeadRoom 事件分析
生活随笔
收集整理的這篇文章主要介紹了
SCN HeadRoom 事件分析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SCN的可能最大值與耗盡問題
? ? 在2012年第一季度的CPU補丁中,包含了一個關于SCN修正的重要變更,這個補丁提示,在異常情況下,Oracle的SCN可能出現異常增長,使得數據庫的一切事務停止,由于SCN不能后退,所以數據庫必須重建,才能夠重用。這個BUG的BUG號是:13489660 - DB-10.2.0.5-MOLECULE-020-CPUJAN2012該BUG修正了SCN的問題。 ? ? 這個BUG的影響在于,Oracle的SCN可能會被異常的增進,而至于極限,導致數據庫無法正常工作,在這種情況下,只能重建數據庫。但是這個風險的發生概率低,因為Oracle會在數據庫內部控制SCN的合理增長,每秒SCN最多增長16348,這會將SCN控制在一個合理的增長范疇內。Oracle使用6 Bytes記錄SCN,也就是48位,其最大值是:
SQL> col scn for 99999999999999999
SQL> select power(2,48) scn from dual;
? ? ? ? ? ? ? ?SCN
------------------
? ?281 4749 7671 0656
---SCN?HeadRoom 可以使用天數 Oracle在內部控制每秒增減的SCN不超過 16K,按照這樣計算,這個數值可以使用大約544年:
SQL> select power(2,48) / 16 / 1024 / 3600 / 24 / 365 from dual;
POWER(2,48)/16/1024/3600/24/365
-------------------------------
? ? ? ? ? ? ? ? ? ? ?544.770078
然而在出現異常時,尤其是當使用DB Link跨數據庫查詢時,SCN會被同步,數據庫之間可以通過dblink來進行數據訪問,當通過dblink進行業務提交的時候,由于數據庫之間存在不同的SCN,因此,為了讓事務一致,Oracle將會以兩者之間較大的SCN來進行同步,更新dblink兩端的數據庫SCN。但是,如果源數據庫出現SCN生成率過高的問題,隨著業務的不斷運行,SCN的異常就會通過dblink傳染到其他相關的數據庫,而dblink使用的頻率越大,這種傳染的速度也就越快。如果企業內部存在網狀的dblink結構,那么這將很容易將SCN的問題擴大到全網,極端情況下會引起大范圍的宕機。
現在測試DB link與檢查點(checkpoint)和SCN
測試的過程如下:1)、獲取remote數據庫系統scn [oracle@ora11] /home/oracle> sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat Oct 24 20:59:02 2015
Copyright (c) 1982, 2013, Oracle. ?All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select dbms_flashback.GET_SYSTEM_CHANGE_NUMBER scn from dual;
? ? ? ?SCN
----------
? ?2264312 ? ?---開始查詢值
2.通過db link進行SCN查詢
---獲取數據庫名稱 set serveroutput on
set feedback off
DECLARE
? ?r_gname ? VARCHAR2 (40);
? ?l_gname ? VARCHAR2 (40);
BEGIN
? ?EXECUTE IMMEDIATE 'select GLOBAL_NAME from global_name@xulq_link'
? ? ? INTO r_gname;
? ?DBMS_OUTPUT.put_line ('gname of remote:' || r_gname);
? ?SELECT GLOBAL_NAME INTO l_gname FROM global_name;
? ?DBMS_OUTPUT.put_line ('gname of locald:' || l_gname);
END;
/
gname of remote:XULQ
gname of locald:SDXJ
--獲取兩個數據庫的scn declare
?r_scn ? ? ?number;
?l_scn ? ? ?number;
?begin
? ? execute immediate
? ? 'select dbms_flashback.GET_SYSTEM_CHANGE_NUMBER@xulq_link from dual' into r_scn;
? ? dbms_output.put_line('scn of remote:'||r_scn);
? ? select dbms_flashback.GET_SYSTEM_CHANGE_NUMBER into l_scn from dual;
? ? dbms_output.put_line('scn of locald:'||l_scn);
?end;
?/
scn of remote:82921684
scn of locald: ?82921684
我們可以看到,通過DB Link查詢后,兩個數據庫的SCN被同步。
手工執行checkpoint,此時可以發現數據庫的checkpoint scn被增進:
SQL> select dbms_flashback.GET_SYSTEM_CHANGE_NUMBER scn from dual;
? ? ? ?SCN
----------
? 82921851 ? ---DBLINK訪問后的,激增值。
SQL> select file#,CHECKPOINT_CHANGE# scn from v$datafile;
? ? ?FILE# ? ? ? ?SCN
---------- ----------
? ? ? ? ?1 ? 82921825
? ? ? ? ?2 ? 82921825
? ? ? ? ?3 ? 82921825
? ? ? ? ?4 ? 82921825
? ? ? ? ?5 ? 82921825
? ? ? ? ?6 ? 82921825
6 rows selected.
產生原因: 這種機制其實是為了滿足分布式事務(Distributed Transaction)的需要,只不過這里通過db link被觸發。
當前SCN最大值 一個數據庫當前最大的可能SCN被稱為"最大合理SCN",該值可以通過如下方式計算:
col scn for 999,999,999,999,999,999
select?
(
? ? (
? ? ? ? (
? ? ? ? ? ? (
? ? ? ? ? ? ? ? ( ??
? ? ? ? ? ? ? ? ? ? (
? ? ? ? ? ? ? ? ? ? ? ? to_char(sysdate,'YYYY')-1988
? ? ? ? ? ? ? ? ? ? )*12+
? ? ? ? ? ? ? ? to_char(sysdate,'mm')-1
? ? ? ? ? ? ? ? )*31+to_char(sysdate,'dd')-1
? ? ? ? ? ? )*24+to_char(sysdate,'hh24')
? ? ? ? )*60+to_char(sysdate,'mi')
? ? )*60+to_char(sysdate,'ss')
) * to_number('ffff','XXXXXXXX')/4 scn
from dual
/
這個算法即SCN算法,以1988年1月1日 00點00時00分開始,每秒計算1個點數,最大SCN為16K。
在CPU補丁中,Oracle提供了一個腳本 scnhealthcheck.sql 用于檢查數據庫當前SCN的剩余情況。
該腳本的算法和以上描述相同,最終將最大合理SCN 減去當前數據庫SCN,計算得出一個指標:HeadRoom。也就是SCN尚余的頂部空間,這個頂部空間最后折合成天數:
以下是這個腳本的內容:
------script begin ---- Rem
Rem $Header: rdbms/admin/scnhealthcheck.sql st_server_tbhukya_bug-13498243/8 2012/01/17 03:37:18 tbhukya Exp $
Rem
Rem scnhealthcheck.sql
Rem
Rem Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.?
Rem
Rem ? ?NAME
Rem ? ? ?scnhealthcheck.sql - Scn Health check
Rem
Rem ? ?DESCRIPTION
Rem ? ? ?Checks scn health of a DB
Rem
Rem ? ?NOTES
Rem ? ? ?.
Rem
Rem ? ?MODIFIED ? (MM/DD/YY)
Rem ? ?tbhukya ? ? 01/11/12 - Created
Rem
Rem
define LOWTHRESHOLD=10
define MIDTHRESHOLD=62
define VERBOSE=FALSE
set veri off;
set feedback off;
set serverout on
DECLARE
?verbose boolean:=&&VERBOSE;
BEGIN
?For C in (
? select?
? ?version,?
? ?date_time,
? ?dbms_flashback.get_system_change_number current_scn,
? ?indicator
? from
? (
? ?select
? ?version,
? ?to_char(SYSDATE,'YYYY/MM/DD HH24:MI:SS') DATE_TIME,
? ?((((
? ? ((to_number(to_char(sysdate,'YYYY'))-1988)*12*31*24*60*60) +
? ? ((to_number(to_char(sysdate,'MM'))-1)*31*24*60*60) +
? ? (((to_number(to_char(sysdate,'DD'))-1))*24*60*60) +
? ? (to_number(to_char(sysdate,'HH24'))*60*60) +
? ? (to_number(to_char(sysdate,'MI'))*60) +
? ? (to_number(to_char(sysdate,'SS')))
? ? ) * (16*1024)) - dbms_flashback.get_system_change_number)
? ?/ (16*1024*60*60*24)
? ?) indicator
? ?from v$instance
? )?
?) LOOP
? dbms_output.put_line( '-----------------------------------------------------'
? ? ? ? ? ? ? ? ? ? ? ? || '---------' );
? dbms_output.put_line( 'ScnHealthCheck' );
? dbms_output.put_line( '-----------------------------------------------------'
? ? ? ? ? ? ? ? ? ? ? ? || '---------' );
? dbms_output.put_line( 'Current Date: '||C.date_time );
? dbms_output.put_line( 'Current SCN: ?'||C.current_scn );
? if (verbose) then
? ? dbms_output.put_line( 'SCN Headroom: '||round(C.indicator,2) );
? end if;
? dbms_output.put_line( 'Version: ? ? ?'||C.version );
? dbms_output.put_line( '-----------------------------------------------------'
? ? ? ? ? ? ? ? ? ? ? ? || '---------' );
? IF C.version > '10.2.0.5.0' and?
? ? ?C.version NOT LIKE '9.2%' THEN
? ? IF C.indicator>&MIDTHRESHOLD THEN?
? ? ? dbms_output.put_line('Result: A - SCN Headroom is good');
? ? ? dbms_output.put_line('Apply the latest recommended patches');
? ? ? dbms_output.put_line('based on your maintenance schedule');
? ? ? IF (C.version < '11.2.0.2') THEN
? ? ? ? dbms_output.put_line('AND set _external_scn_rejection_threshold_hours='
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|| '24 after apply.');
? ? ? END IF;
? ? ELSIF C.indicator<=&LOWTHRESHOLD THEN
? ? ? dbms_output.put_line('Result: C - SCN Headroom is low');
? ? ? dbms_output.put_line('If you have not already done so apply' );
? ? ? dbms_output.put_line('the latest recommended patches right now' );
? ? ? IF (C.version < '11.2.0.2') THEN
? ? ? ? dbms_output.put_line('set _external_scn_rejection_threshold_hours=24 '
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|| 'after apply');
? ? ? END IF;
? ? ? dbms_output.put_line('AND contact Oracle support immediately.' );
? ? ELSE
? ? ? dbms_output.put_line('Result: B - SCN Headroom is low');
? ? ? dbms_output.put_line('If you have not already done so apply' );
? ? ? dbms_output.put_line('the latest recommended patches right now');
? ? ? IF (C.version < '11.2.0.2') THEN
? ? ? ? dbms_output.put_line('AND set _external_scn_rejection_threshold_hours='
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?||'24 after apply.');
? ? ? END IF;
? ? END IF;
? ELSE
? ? IF C.indicator<=&MIDTHRESHOLD THEN
? ? ? dbms_output.put_line('Result: C - SCN Headroom is low');
? ? ? dbms_output.put_line('If you have not already done so apply' );
? ? ? dbms_output.put_line('the latest recommended patches right now' );
? ? ? IF (C.version >= '10.1.0.5.0' and?
? ? ? ? ? C.version <= '10.2.0.5.0' and?
? ? ? ? ? C.version NOT LIKE '9.2%') THEN
? ? ? ? dbms_output.put_line(', set _external_scn_rejection_threshold_hours=24'
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|| ' after apply');
? ? ? END IF;
? ? ? dbms_output.put_line('AND contact Oracle support immediately.' );
? ? ELSE
? ? ? dbms_output.put_line('Result: A - SCN Headroom is good');
? ? ? dbms_output.put_line('Apply the latest recommended patches');
? ? ? dbms_output.put_line('based on your maintenance schedule ');
? ? ? IF (C.version >= '10.1.0.5.0' and
? ? ? ? ? C.version <= '10.2.0.5.0' and
? ? ? ? ? C.version NOT LIKE '9.2%') THEN
? ? ? ?dbms_output.put_line('AND set _external_scn_rejection_threshold_hours=24'
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|| ' after apply.');
? ? ? END IF;
? ? END IF;
? END IF;
? dbms_output.put_line(
? ? 'For further information review MOS document id 1393363.1');
? dbms_output.put_line( '-----------------------------------------------------'
? ? ? ? ? ? ? ? ? ? ? ? || '---------' );
?END LOOP;
end;
/
--scrippt end -----
--以上,腳本可以直接使用
一般應用補丁之后,一個新的隱含參數 _external_scn_rejection_threshold_hours 引入,通常設置該參數為 24 小時:_external_scn_rejection_threshold_hours=24
這個設置降低了SCN Headroom的頂部空間,以前缺省的設置容量至少為31天,降低為 24 小時,可以增大SCN允許增長的合理空間。但是如果不加控制,SCN仍然可能會超過最大的合理范圍,導致數據庫問題。
這個問題的影響會極其嚴重,我們建議用戶檢驗當前數據庫的SCN使用情況,
在SCN告警閾值達到時,數據庫中可能出現以下錯誤信息:
Advanced SCN by 8381 minutes worth to Ox0bad.4ab15e1,by distributed transaction remote logon,remote DB:ORCL.
Warning - High Database SCN: Current SCN value is 0x0b7b.0008e40b, threshold SCN value is 0x0b75.055dc000
If you have not previously reported this warning on this database, please notify Oracle Support so that additional diagnosis can be performed.
Warning: The SCN headroom for this database is only NN days!
Warning: The SCN headroom for this database is only N hours!
Rejected the attempt to advance SCN over limit by 984 hours worth to 0x0c00.0000ff66, by distributed transaction remote logon, remote DB: DB.ORCL.ORACLE.COM.
Client info : DB logon user SYS, machine sun, program sqlplus@orcl (TNS V1-V3), and OS user oracle
Rejected the attempt to advance SCN over limit by 9875 hours worth to 0x0c00.000003e6, by distributed transaction logon, remote DB: DB.ORCL.ORACLE.COM.
MOS參考文檔:
NOTE:1376995.1 - Information on the System Change Number (SCN) and how it is used in the Oracle Database
NOTE:1393363.1 - Installing, Executing and Interpreting output from the "SCNhealthcheck.sql" script
NOTE:1388639.1 - Evidence to collect when reporting "high SCN rate" issues to Oracle Support
NOTE:1393360.1 - ORA-19706 and Related Alert Log Messages
總結
以上是生活随笔為你收集整理的SCN HeadRoom 事件分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51单片机的特殊功能寄存器(SFR)
- 下一篇: 《WebAssembly 权威指南》(6