升級失敗後,資料庫降級方案(flashback database)

lovehewenyu發表於2013-08-08

升級失敗後,資料庫降級方案(flashback database

 

環境:Oracle 11.2.0.1 rac on redhat 5.8

Flashback database準備工作

檢視是否flashback database功能

sys@RACDB> select log_mode,open_mode,flashback_on from v$database;

LOG_MODE     OPEN_MODE            FLASHBACK_ON

------------ -------------------- ------------------

ARCHIVELOG   READ WRITE           NO --未開啟flashback database 功能

 

檢視是否設定了閃回目錄、閃回目錄空間大小

sys@RACDB> show parameter db_recovery

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest                string

db_recovery_file_dest_size           big integer 0

--顯然我們沒有設定,下面為設定後

alter system set db_recovery_file_dest='+DATA' scope=spfile sid='*'; --重啟後生效

alter system set db_recovery_file_dest_size=4g;

sys@RACDB> show parameter db_recovery

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest                string      +DATA

db_recovery_file_dest_size           big integer 4G

 

設定閃回保留期

sys@RACDB> show parameter db_flashback

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_flashback_retention_target        integer     1440   --預設單位為分鐘

 

Flashback database開啟工作

開啟flashback database功能

sys@RACDB> alter database flashback on;

Database altered.

sys@RACDB> select status from gv$instance;

STATUS

------------

OPEN

OPEN

sys@RACDB> select log_mode,open_mode,flashback_on from v$database;

LOG_MODE     OPEN_MODE            FLASHBACK_ON

------------ -------------------- ------------------

ARCHIVELOG   READ WRITE           YES -開啟了flashback database功能

 

oracle 10.2.0.1

開啟flashback database需要在mount,且只有一個例項的情況下,否則會報錯

ORA-38759: Database must be mounted by only one instance and not open.

oracle 11.2.0.1

開啟flashback databaseopen狀態下,且多個例項共存,沒有任何問題

 

檢視允許閃回的最早時間點

select oldest_flashback_scn old_flhbck_scn,oldest_flashback_time old_flhbck_tim,

retention_target rete_trgt,flashback_size/1024/1024 flhbck_siz,

estimated_flashback_size/1024/1024 est_flhbck_size

from v$flashback_database_log;

OLD_FLHBCK_SCN OLD_FLHBCK_TIM       RETE_TRGT FLHBCK_SIZ EST_FLHBCK_SIZE

-------------- ------------------- ---------- ---------- ---------------

       1602195 2013-08-08 16:48:34       1440     15.625               0

 

Flashback database 使用範例

1、建立一個restore point

升級失敗後,降級時使用flashback database to restore point upgrade_dou;

sys@RACDB> create restore point upgrade_dou guarantee flashback database;

Restore point created.

sys@RACDB> select oldest_flashback_scn old_flhbck_scn,oldest_flashback_time old_flhbck_tim,

  2  retention_target rete_trgt,flashback_size/1024/1024 flhbck_siz,

  3  estimated_flashback_size/1024/1024 est_flhbck_size

  4  from v$flashback_database_log;

OLD_FLHBCK_SCN OLD_FLHBCK_TIM       RETE_TRGT FLHBCK_SIZ EST_FLHBCK_SIZE

-------------- ------------------- ---------- ---------- ---------------

       1602195 2013-08-08 16:48:34       1440     15.625        143.8125

 

2flashback database使用restore point

降級時

資料庫必須是mount狀態

sys@RACDB> flashback database to restore point upgrade_dou;

flashback database to restore point upgrade_dou

*

ERROR at line 1:

ORA-38757: Database must be mounted and not open to FLASHBACK.

Flashback database必須resetlogs open資料庫

sys@RACDB> alter database open;

alter database open

*

ERROR at line 1:

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

RAC環境中alter database open resetlogs;時有且只有一個例項執行resetlogs

idle> select status from gv$instance;

 

STATUS

------------

MOUNTED

MOUNTED

idle> alter database open resetlogs;

alter database open resetlogs

*

ERROR at line 1:

ORA-38777: database must not be started in any other instance

關閉一個節點

idle> select status from gv$instance;

STATUS

------------

MOUNTED

idle> alter database open resetlogs;

Database altered.

檢查RAC節點恢復情況

另一個節點也open

idle> select status from gv$instance;

STATUS

------------

OPEN

OPEN

idle> select current_scn from gv$database;

CURRENT_SCN

-----------

    1628773

1628774

 

 

 

附表

 

檢視允許閃回的最早時間點

select oldest_flashback_scn old_flhbck_scn,oldest_flashback_time old_flhbck_tim,

retention_target rete_trgt,flashback_size/1024/1024 flhbck_siz,

estimated_flashback_size/1024/1024 est_flhbck_size

from v$flashback_database_log;

 

檢視sga中分配的閃回空間大小

select * from v$sgastat where name like 'flashback%'; 

POOL         NAME                            BYTES

------------ -------------------------- ----------

shared pool  flashback generation buff     3981204

shared pool  flashback_marker_cache_si        9196

 

檢視閃回區的使用情況

select name,space_limit/1024/1024 sp_limt,space_used/1024/1024 sp_usd,space_reclaimable/1024/1024 sp_recl,number_of_files num_fils from v$recovery_file_dest;

NAME

----------------------------------------------------------------------------------------------------

   SP_LIMT     SP_USD    SP_RECL   NUM_FILS

---------- ---------- ---------- ----------

+DATA

      4096         36          0          3

 

 

使用flashback database閃回資料庫

    步驟(前提歸檔日誌可用)

        關閉資料庫

        啟動資料庫到mount狀態(exclusive模式)

        閃回至某個時間點,SCNlog sequence number

        使用resetlogs開啟資料庫

    1.使用sqlplus實現閃回

        可以接受一個時間標記或一個系統改變號實參

        sqlplus幾種常用的閃回資料庫方法

            FLASHBACK [STANDBY] DATABASE []  TO [BEFORE] SCN    --基於SCN閃回

            FLASHBACK [STANDBY] DATABASE []  TO [BEFORE] TIMESTMP --基於時間戳閃回

            FLASHBACK [STANDBY] DATABASE []  TO [BEFORE] RESTORE POINT --基於時點閃回

        如下面的示例:

            SQL> flashback database to timestamp('2010-10-24 13:04:30','yyyy-mm-dd hh24:mi:ss');

            SQL> flashback database to scn 918987;

            SQL> flashback database ro restore point b1_load;

 

2.使用RMAN進行flashback database

        使用RMAN進行閃回資料庫的幾種常用辦法

            RMAN> flashback database to scn=918987;

            RMAN> flashback database to sequence=85  thread=1;

 

 

 

 

 

參考文獻:

http://blog.csdn.net/robinson_0612/article/details/6100429

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26442936/viewspace-768080/,如需轉載,請註明出處,否則將追究法律責任。

相關文章