熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

DataGuard環境搭建

2022-06-13   來源: Oracle 

  自己做的工作一直涉及的是單實例數據庫對容災也沒有特別高的要求平時基本上是靠rman備份或是手工邏輯備份所以一直想做一些關於dataguard的實驗去驗證一些感覺很棒的操作本文參照了三思的一些文檔搭建了一套這樣的環境很是興奮雖然對理論知識不是太理解但是用實踐來驗證理論會更好的理解吧下面是自己搭建dataguard環境時的一些簡要記錄
    創建主庫即在一台物理機上安裝數據庫軟件及創建數據庫作為主庫並啟動到force logging 狀態(alter database force logging;)
    創建備庫在另一台物理機上只安裝數據庫軟件作為備庫所有路徑與主庫一致
    在主庫上創建備庫的控制文件SQL> alter database create standbycontrolfile as d:\backup\controlctl;
    關閉主庫把主庫所有數據文件(如果備庫沒有相關目錄那麼連帶目錄一並)拷貝到備庫的相應位置把創建的備庫控制文件拷貝到拷貝到相應位置然後復制與主庫一樣的份數及名稱
    拷貝主庫的密碼文件到備庫的相應文件中
    修改主庫的spfile 文件主要是添加下列內容修改的時候創建pfile修改後再創建spfile:
    *log_archive_format=%T%S%rARC
    *DB_UNIQUE_NAME=primary
    *log_archive_config=DG_CONFIG=(primarystandby)
    *log_archive_dest_=location=F:\flash_recover_area\ORCL\ARCHIVELOGVALID_FOR=(ALL_LOGFILESALL_ROLES) DB_UNIQUE_NAME=PRIMARY
    *log_archive_dest_=SERVICE=standbyarch ASYNC VALID_FOR=(ONLINE_LOGFILESPRIMARY_ROLE) DB_UNIQUE_NAME=standby
    *STANDBY_FILE_MANAGEMENT=AUTO
    *LOG_ARCHIVE_DEST_STATE_=ENABLE
    *LOG_ARCHIVE_DEST_STATE_=ENABLE
    *FAL_SERVER=standby
    *FAL_CLIENT=primary
    修改主庫的tns添加下列內容
    PRIMARY =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = bcde)(PORT = ))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = orcl)
    )
    )
    STANDBY =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = orcl)
    )
    )
    當然備庫的spfile也得修改主要添加下列內容
    *log_archive_format=%T%S%rARC
    *DB_UNIQUE_NAME=standby
    *log_archive_config=DG_CONFIG=(primarystandby)
    *log_archive_dest_=location=F:\flash_recover_area\ORCL\ARCHIVELOGVALID_FOR=(ALL_LOGFILESALL_ROLES) DB_UNIQUE_NAME=standby
    *log_archive_dest_=SERVICE=primaryarch ASYNC VALID_FOR=(ONLINE_LOGFILESPRIMARY_ROLE) DB_UNIQUE_NAME=primary
    *STANDBY_FILE_MANAGEMENT=AUTO
    *LOG_ARCHIVE_DEST_STATE_=ENABLE
    *LOG_ARCHIVE_DEST_STATE_=ENABLE
    *FAL_CLIENT=standby
    *FAL_SERVER=primary
    修改備庫的tns添加下列內容
    PRIMARY =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = orcl)
    )
    )
    STANDBY =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
    )
    (CONNECT_DATA =
    (SERVICE_NAME = standby)
    )
    )
    由於備庫沒有實力服務所以在備庫中創建實例的服務
    用oradim工具創建備庫orcl實例 ?
    oradimnew sid orcl startmode m ?
    oradimedit sid orcl startmode a ?
    其實到這裡配置基本上就結束了下面就是啟動和驗證是否可用了
    啟動及關閉順序啟動時先啟動備庫再主庫關閉時先關閉主庫再備庫
    在備庫將實例啟動到mount 狀態
    SQL> startup nomount;
    SQL>alter database mount standby database ;
    SQL>alter database recover managed standby database disconnect from session;
    SQL>alter database recover managed standby database cancel;
    備庫啟監聽
    $lsnrctl start
    主庫啟實例
    SQL> startup;
    主庫啟監聽
    $lsnrctl start
    在主庫驗證歸檔目錄是否有效
    SQL> SELECT STATUSDESTINATION ERROR FROM V$ARCHIVE_DEST;
    如果有錯誤要排查原因
    SQL> alter system switch logfile;
    SQL> select max(sequence#) from v$archived_log;
    主備切換
    主庫
    SQL> select switchover_status fromv$database;
    SWITCHOVER_STATUS
   
    TO STANDBY
    SQL> alter database commit to switchoverto physical standby with session shutdown ;
    數據庫已更改
    SQL> alter database commit to switchoverto physical standby;
    alter database commit to switchover tophysical standby
    *
    第 行出現錯誤
    ORA: 未裝載數據庫
    SQL> shutdown immediate;
    ORA: 未裝載數據庫
    ORACLE 例程已經關閉
    SQL> startup
    ORACLE 例程已經啟動
    Total System Global Area  bytes
    Fixed Size                  bytes
    Variable Size             bytes
    Database Buffers          bytes
    Redo Buffers                bytes
    數據庫裝載完畢
    數據庫已經打開
    SQL> alter database commit to switchoverto physical standby;
    數據庫已更改
    SQL> select switchover_status fromv$database;
    SWITCHOVER_STATUS
   
    TO PRIMARY
    SQL> shutdown immediate;
    數據庫已經關閉
    已經卸載數據庫
    ORACLE 例程已經關閉
    SQL> startup nomount;

  ORACLE 例程已經啟動
    Total System Global Area  bytes
    Fixed Size                  bytes
    Variable Size             bytes
    Database Buffers          bytes
    Redo Buffers                bytes
    SQL> alter database mount standbydatabase;
    數據庫已更改
    SQL> alter database recover managedstandby database disconnect from session;
    數據庫已更改
    備庫
    SQL> select switchover_status fromv$database;
    SWITCHOVER_STATUS
   
    SWITCHOVER PENDING
    SQL> alter database commit to switchoverto primary;
    alter database commit to switchover toprimary
    *
    ERROR at line :
    ORA: media recovery required
    開始介質恢復
    SQL> alter database recover managedstandby database finish;
    Database altered
    SQL> alter database commit to switchoverto primary;
    Database altered
    SQL> shutdown immediate;
    ORA: database not open
    Database dismounted
    ORACLE instance shut down
    SQL> startup;
    ORACLE instance started
    Total System Global Area  bytes
    Fixed Size                  bytes
    Variable Size             bytes
    Database Buffers          bytes
    Redo Buffers                bytes
    Database mounted
    Database opened
    SQL> alter system switch logfile;
    System altered
    SQL> select switchover_status fromv$database;
    SWITCHOVER_STATUS
   
    TO STANDBY
    以下是介質恢復時的alert 日志
    alterdatabase commit to switchover to primary
    Maximumwait for role transition is minutes
    Databasenot available for switchover
    EndOfREDO archived log file has beenreceived
    EndOfREDO archived log file has not beenrecovered
    Archived log files detected beyondEndOfREDO
    Incomplete recovery SCN:: archiveSCN::
    Databasenot available for switchover
    EndOfREDO archived log file has beenreceived
    EndOfREDO archived log file has not beenrecovered
    Archived log files detected beyondEndOfREDO
    Incomplete recovery SCN:: archiveSCN::
    Switchover:Media recovery required standby not in limbo
    ORAsignalled during: alter database commit to switchover to primary…
    WedSep ::
    alterdatabase recover managed standby database finish
    SerialMedia Recovery started
    ManagedStandby Recovery not using Real Time Apply
    WARNING!Recovering data file from a fuzzy file If not the current file
    itmight be an online backup taken without entering the begin backup command
    WARNING!Recovering data file from a fuzzy file If not the current file
    itmight be an online backup taken without entering the begin backup command
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    WedSep ::
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    WedSep ::
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    WedSep ::
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    WedSep ::
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    MediaRecovery Log F:\FLASH_RECOVER_AREA\ORCL\ARCHIVELOG\ARC
    IdentifiedEndOfRedo for thread sequence
    Resettingstandby activation ID xca)
    MediaRecovery EndOfRedo indicator encountered
    MediaRecovery Applied through change
    Completed:alter database recover managed standby database finish
    好像是當時主庫傳過來的歸檔日志都沒有應用另外注意到原始主庫發出歸檔命令時先歸檔到主庫中後歸檔到備庫中切換之後現在的主庫發出歸檔命令後還是先歸檔到原來的主庫(即現在的備庫)然後才是自己


From:http://tw.wingwit.com/Article/program/Oracle/201311/18923.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.