DataGuard搭建物理StandBy

壹頁書發表於2014-10-30
實驗使用DataGuard搭建一套物理StandBy環境

主庫Primary:192.168.1.1
備庫StandBy:192.168.1.2

主要步驟
1.主庫設定歸檔模式,並且設定強制日誌
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
SQL> alter database force logging;
Database altered.

2.主庫,備庫設定tns和監聽器
主庫和備庫的tnsnames.ora設定相同
PRIMARY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

STANDBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.2)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )
主庫和備庫的監聽器IP地址不同
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /home/oracle/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = orcl)
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.1)(PORT = 1521))
  )

ADR_BASE_LISTENER = /home/oracle/app/oracle

3.備份主庫
rman target /
backup database;
backup current controlfile for standby;

4.主庫建立密碼檔案
在$ORACLE_HOME/dbs目錄下建立密碼檔案

[oracle@master dbs]$ pwd
/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@master dbs]$ orapwd file=orapworcl password=123456

5.將主庫的備份,spfile和密碼檔案傳輸到備庫相同的位置(若備庫不存在該位置則建立)

6.修改主庫spfile,重啟資料庫使設定生效
alter system set db_unique_name=orcl scope=spfile;
alter system set log_archive_dest_2='service=standby valid_for=(online_logfiles,primary_role) db_unique_name=orcl' scope=spfile;
alter system set fal_client=primary;
alter system set fal_server=standby;
alter system set standby_file_management=auto scope=spfile;

7.啟動備庫至nomount,修改備庫spfile
(spfile中的目錄在備庫必須存在,可以先匯出pfile,然後建立相關的目錄)

alter system set db_unique_name=orcl scope=spfile;
alter system set log_archive_dest_2='service=primary valid_for=(online_logfiles,standby_role) db_unique_name=orcl' scope=spfile;
alter system set fal_client=standby;
alter system set fal_server=primary;
alter system set standby_file_management=auto scope=spfile;

8.主庫執行duplicate
rman target / auxiliary sys/123456@standby
duplicate target database for standby nofilenamecheck;

如果主庫備份包括歸檔日誌,
backup database;
backup current controlfile for standby;
sql "alter system archive log current";
backup filesperset 10 archivelog all;

則使用如下命令,直接在備庫應用歸檔
duplicate target database for standby dorecover nofilenamecheck;

9.啟用物理standby
startup nomount;
ALTER DATABASE MOUNT STANDBY DATABASE;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

如果需要停止物理standby,則執行如下命令
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; 


搭建過程需要注意兩點
1.密碼檔案必須從主庫傳輸到備庫,不能使用相同的密碼在備庫建立密碼檔案
2.如果備份中有歸檔執行
duplicate target database for standby dorecover nofilenamecheck;
如果備份中沒有歸檔日誌,則執行
duplicate target database for standby nofilenamecheck;
否則報錯如下:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 03/28/2012 12:20:16
RMAN-03015: error occurred in stored script. Memory Script
RMAN-06026: some targets not found - aborting restore
RMAN-06024: no backup or copy of the control file found to restore

dorecover
從目標資料庫用歸檔日誌備份恢復備用資料庫。一旦備用資料庫的建立完成,RMAN將對備用資料庫應用主資料庫中的所有歸檔日誌,一直到RMAN中註冊的最新的歸檔日誌。

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

相關文章