DataGuard部署

環境準備
 
主庫 primary     10.63.230.10
備庫 standby     10.63.230.13
 
軟件版本
 
Oracle 11.2.0.4.0
 
搭建步驟
--主庫
1.查看歸檔開啓狀態
SQL> archive log list;

2.建立歸檔目錄數據庫

mkidr /oradata/arch

3.開啓歸檔session

SQL> alter database mount;
SQL> alter database archivelog;
SQL> alter system switch logfile;

4.修改主庫屬性oracle

SQL> alter database force logging;
SQL> select FORCE_LOGGING from v$database; 

5.在主庫建立密碼文件、參數文件、以及standby控制文件app

SQL> create pfile='/home/oracle/pfile.ora' from spfile;

6.密碼文件能夠直接用現有的async

ls $ORACLE_HOME/dbs/orapw*

7.建立standby控制文件性能

SQL> alter database create standby controlfile as '/home/oracle/controlstd.ctl';

8.主庫TNS配置spa

TEST=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

TESTBAK=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.13)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TESTBAK)
    )
  )

9.主庫備份數據庫線程

RMAN> run {
crosscheck backup ;
crosscheck archivelog all;
crosscheck backupset ;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
backup as compressed backupset full database format '/oradata/rman/full_%d_%t_%s_%p' plus archivelog format '/oradata/rman/arch_%d_%t_%s_%p.bkp';
}

10.備份完畢後將rman備份文件,standby控制文件,密碼文件,參數文件一塊兒傳到備庫rest

參數文件和standby控制文件放在/home/oracle/目錄下日誌

密碼文件放在 $ORACLE_HOME/dbs/目錄下

 

注:若是目錄屬主不是 oracle.oinstall或者oracle.dba 須要修改目錄權限,文件傳完後,檢查下文件的用戶和組。

 

--備庫

1.建立數據庫目錄,根據本身的參數文件中的參數目錄而定

mkdir -p /u01/app/oracle/admin/test/adump
mkdir -p /oradata/rman
mkdir -p /oradata/arch
mkdir -p /oradata/test

2.使用參數文件開啓數據庫

SQL> startup nomount pfile='/home/oracle/pfile.ora';

3.導入standby控制文件

RMAN> restore controlfile from '/home/oracle/controlstd.ctl';

4.恢復數據文件

SQL> alter database mount;
RMAN> catalog start with '/oradata/rman/';
RMAN> restore database;

5.恢復歸檔文件

RMAN> recover database;

6.備庫TNS配置

TEST=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

TESTBAK=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.63.230.13)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TESTBAK)
    )
  )

7.建立standby redo log

在使用最大保護模式或是最大可用模式的時候須要在standby數據庫建立standby redo log,對於最大性能模式能夠不用建立standby redo log
SQL> alter database add standby logfile
group 4 ('/oradata/test/std_redo04a.log') size 100m,
group 5 ('/oradata/test/std_redo05a.log') size 100m,
group 6 ('/oradata/test/std_redo06a.log') size 100m,
group 7 ('/oradata/test/std_redo07a.log') size 100m;
SQL> alter database clear logfile group 1;
SQL> alter database clear logfile group 2;
SQL> alter database clear logfile group 3;
添加standby日誌文件的規則:
 standby日誌最少應該比redo log 多一組。推薦的備重作日誌數依賴於主數據庫上的線程數。
 (每線程日誌文件最大數目 + 1 ) * 線程數
不然standby日誌在應用時報以下信息:
RFS[1]: No standby redo logfiles created

RFS[1]: Archived Log: '/oradata/arch/1_30_633287861.dbf'

在主庫添加完standby logfile後,當主庫切換爲standby角色後會自動使用standby redo logfile,具體應用信息以下:

RFS[1]: Successfully opened standby log 4: '/oradata/test/std_redo04a.log'

 

 修改主備庫參數

主庫primary

SQL> alter system set db_unique_name='test' scope=spfile;
SQL> alter system set fal_server='testbak' sid='*'scope=both;
SQL> alter system set fal_client='test' sid='*' scope=both; 
SQL> alter system set standby_file_management=auto sid='*' scope=both;
SQL> alter system set log_archive_config='dg_config=(test,testbak)' sid='*' scope=both;
SQL> alter system set log_archive_dest_2='service=testbak lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=testbak' sid='*' scope=both;
SQL> alter system set log_archive_dest_state_2=enable;

 

備庫standby

SQL> alter system set db_unique_name='testbak' scope=spfile;
SQL> alter system set fal_server='test' sid='*'scope=both;
SQL> alter system set fal_client='testbak' sid='*' scope=both; 
SQL> alter system set standby_file_management=auto sid='*' scope=both;
SQL> alter system set log_archive_config='dg_config=(test,testbak)' sid='*' scope=both;
SQL> alter system set log_archive_dest_2='service=test lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=test' sid='*' scope=both;
SQL> alter system set log_archive_dest_state_2=enable;

 

開啓DG(10g不open)

SQL> alter database open;
SQL> alter database recover managed standby database disconnect from session using current logfile;
SQL> select process,client_process,sequence#,status from v$managed_standby;

停用DG

SQL> alter database recover managed standby database cancel;

若是主庫傳不過來歸檔,能夠經過在主庫側手工修改參數以下:

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2='DEFER' SCOPE=MEMORY;
SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2='ENABLE' SCOPE=MEMORY;

 

至此dg搭建完畢

查詢dg延遲

SQL> col value for a20
SQL> col time_computed for a30
SQL> col name for a25
SQL> col unit for a30
SQL> col datum_time for a30
SQL> set line 400
SQL> select * from v$dataguard_stats;
相關文章
相關標籤/搜索