Oracle的DBMS_SCN修正以及SCN的auto-rollover新特性

技術小能手發表於2018-03-16

在 Oracle 11.2.0.2 之後,隨著一系列 SCN 耗盡問題的出現,很多補丁湧現出來,一個新的 Package 增加進來。

這個 Package 就是 DBMS_SCN。

如果你的資料庫中存在這個 Package,也就意味著你已經安裝具備了關於 DB Link 的修正補丁。

以下是這個包的主要函式過程以及說明,這個內容來自 Oracle 11.2.0.4 版本平臺:

Rem

Rem $Header: rdbms/admin/dbmsscnc.sql /st_rdbms_11.2.0/1 2013/04/18 23:05:40 vgokhale Exp $

Rem

Rem dbmsscn.sql

Rem

Rem Copyright (c) 2012, 2013, Oracle and/or its affiliates. 

Rem All rights reserved. 

Rem

Rem    NAME

Rem      dbmsscnc.sql - dbms_scn package definition

Rem

Rem    DESCRIPTION

Rem      

Rem

Rem    NOTES

Rem      

Rem

Rem    MODIFIED   (MM/DD/YY)

Rem    mtiwary     05/26/12 - Declarations and definitions related to DBMS_SCN

Rem                           package.

Rem    mtiwary     05/26/12 - Created

Rem

Rem

Rem    BEGIN SQL_FILE_METADATA 

Rem    SQL_SOURCE_FILE: rdbms/admin/dbmsscn.sql 

Rem    SQL_SHIPPED_FILE: 

Rem    SQL_PHASE: 

Rem    SQL_STARTUP_MODE: NORMAL 

Rem    SQL_IGNORABLE_ERRORS: NONE 

Rem    SQL_CALLING_FILE: 

Rem    END SQL_FILE_METADATA

SET ECHO ON

SET FEEDBACK 1

SET NUMWIDTH 10

SET LINESIZE 80

SET TRIMSPOOL ON

SET TAB OFF

SET PAGESIZE 100

CREATE OR REPLACE LIBRARY DBMS_SCN_LIB TRUSTED AS STATIC;

/

CREATE OR REPLACE PACKAGE DBMS_SCN AUTHID CURRENT_USER IS

DBMS_SCN_API_MAJOR_VERSION  CONSTANT NUMBER := 1; 

DBMS_SCN_API_MINOR_VERSION  CONSTANT NUMBER := 0;

PROCEDURE GetCurrentSCNParams(

                rsl      OUT number,

                headroom_in_scn OUT number,

                headroom_in_sec OUT number,

                cur_scn_compat OUT number,

                max_scn_compat OUT number);

--      Currently no exceptions are thrown.

--      rsl             - Reasonable SCN Limit as of `now`

--      headroom_in_scn - Difference between current SCN and RSL

--      headroom_in_sec - number of seconds it would take to reach RSL

--                        assuming a constant SCN consumption rate associated

--                        with current SCN compatibility level

--      cur_scn_compat  - current value of SCN compatibility

--      max_scn_compat  - max value of SCN compatibility this database

--                        understands

FUNCTION GetSCNParamsByCompat(

                compat IN number,

                rsl           OUT number,

                headroom_in_scn OUT number,

                headroom_in_sec OUT number

         ) RETURN boolean;

--     compat           -- SCN compatibility value

--     rsl              -- Reasonable SCN Limit

--     headroom_in_scn  -- Difference between current SCN and RSL

--     headroom_in_sec  -- number of seconds it would take to reach RSL

--                         assuming a constant SCN consumption rate associated

--                         with specified database SCN compatibility

--

--     Returns False if `compat` parameter value is invalid, and OUT parameters

--     are not updated.

PROCEDURE GetSCNAutoRolloverParams(

                effective_auto_rollover_ts OUT DATE,

                target_compat OUT number,

                is_enabled OUT boolean);

--      effective_auto_rollover_ts  - timestamp at which rollover becomes

--                                    effective

--      target_compat               - SCN compatibility value this database

--                                    will move to, as a result of

--                                    auto-rollover

--      is_enabled                  - TRUE if auto-rollover feature is

--                                    currently enabled

PROCEDURE EnableAutoRollover;

PROCEDURE DisableAutoRollover;

END DBMS_SCN;

/

這裡就可以看到 auto-rollover 的自動 SCN 相容性終止時間,也就是說,在不同的相容性設定中,SCN 的演算法不同,但是內建了天然的演算法過期時間。

在此之後,可以通過命令修改資料庫的 SCN 相容性演算法:

SQL> ALTER DATABASE SET SCN COMPATIBILITY 2;

Database altered.

從高階別向低階別修改,需要資料庫在 Mount 狀態:

SQL> ALTER DATABASE SET SCN COMPATIBILITY 2;

ALTER DATABASE SET SCN COMPATIBILITY 2

*

ERROR at line 1:

ORA-01126: database must be mounted in this instance and not open in any instance

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 4609830912 bytes

Fixed Size   2260888 bytes

Variable Size   989855848 bytes

Database Buffers  3607101440 bytes

Redo Buffers    10612736 bytes

Database mounted.

SQL> ALTER DATABASE SET SCN COMPATIBILITY 2;

Database altered.

SQL> alter database open;

Database altered.

這是一個非常重要的變化。


原文釋出時間為:2018-03-16

本文作者:蓋國強

本文來自雲棲社群合作伙伴“資料和雲”,瞭解相關資訊可以關注“資料和雲”微信公眾號


相關文章