天天看點

oracle ADG for windows install steps

環境介紹:

windows 2012 R2*2台

主庫:安裝oracle軟體、監聽、執行個體

備庫:安裝oracle軟體、監聽

資料庫版本:11.2.0.4

主庫:orcl

備庫:prod

1、主庫

create pfile='C:\Users\Administrator\Desktop\file\pfile.ora' from spfile;

alter database force logging;

alter system set log_archive_config='DG_CONFIG=(orcl,prod)' scope=spfile;

alter system set log_archive_dest_1='location=C:\app\archive valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' scope=both sid='';

alter system set log_archive_dest_2='service=prod LGWR ASYNC valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=prod' scope=both sid='';

alter system set log_archive_dest_state_1='enable' scope=both sid='';

alter system set log_archive_dest_state_2='enable' scope=both sid='';

alter system set fal_client='orcl' scope=both sid='';

alter system set fal_server='prod' scope=both sid='';

alter system set standby_file_management='AUTO' scope=both sid='';

alter system set db_file_name_convert='C:\app\datafiles\orcl\','C:\app\datafiles\prod\' scope=spfile sid='';

alter system set log_file_name_convert='C:\app\datafiles\orcl\','C:\app\datafiles\prod\' scope=spfile sid='*';

SQL> create pfile='C:\Users\Administrator\Desktop\file\pfilebak.ora' from spfile;

2、備庫建立目錄

歸檔目錄 C:\app\archive

資料檔案目錄 C:\app\datafiles\prod\

adump目錄 C:\app\Administrator\admin\prod\adump

3、主庫備份

rman target /

run{

allocate channel a1 device type disk;

allocate channel a2 device type disk;

allocate channel a3 device type disk;

crosscheck archivelog all;

sql 'alter system archive log current';

backup full database format='C:\Users\Administrator\Desktop\file\full%U%T' include current controlfile for standby;

backup current controlfile for standby format 'C:\Users\Administrator\Desktop\file\control01.ctl';

backup archivelog all format 'C:\Users\Administrator\Desktop\file\arch%d%T%U.arc';

release channel a1;

release channel a2;

release channel a3;

}

4、拷貝檔案

密碼檔案在$ORACLE_HOME/database

将密碼檔案(需要改sid)、pfile、redo、temp、拷貝到備庫相應目錄。

5、修改host檔案

192.168.3.2 WIN-JP7MSEND1SD

192.168.3.3 WIN-KL9BBQ52F5R

6、主備庫tnsnames一緻

7、修改備庫pfile檔案

更改pfile檔案

db_name='orcl'應與主庫一緻

.db_unique_name='prod'

.audit_file_dest='C:\app\Administrator\admin\prod\adump' 注意路徑

log_archive_dest_1='C:\app\archive'

.db_recovery_file_dest

oracle_base

删除log_archive_dest_2、log_archive_dest_state_1

修改

fal_client='prod'

.fal_server='orcl'

.log_archive_config='DG_CONFIG=(orcl,prod)'

.log_archive_dest_1='location=C:\app\archive valid_for=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prod'

*檢查檔案中的路徑是否正确***

8、備庫添加服務

oradim -new -sid prod -startmode auto

set ORACLE_SID=prod

9、恢複備庫

sql>startup nomount pfile='C:\Users\Administrator\Desktop\file\pfilebak.ora';

sql>create spfile from pfile='C:\Users\Administrator\Desktop\file\pfilebak.ora';

若有需求更改資料檔案目錄可通過

rman target / nocatalog

RMAN> restore standby controlfile from 'C:\Users\Administrator\Desktop\file\control01.ctl';

SQL>alter database mount;

catalog start with 'C:\Users\Administrator\Desktop\file\';

run

{

allocate channel c1 device type disk;

allocate channel c2 device type disk;

allocate channel c3 device type disk;

allocate channel c4 device type disk;

set newname for datafile 1 to 'C:\app\datafiles\prod\system01.dbf';

set newname for datafile 2 to 'C:\app\datafiles\prod\sysaux01.dbf';

set newname for datafile 3 to 'C:\app\datafiles\prod\undotbs01.dbf';

set newname for datafile 4 to 'C:\app\datafiles\prod\users01.dbf';

set newname for datafile 5 to 'C:\app\datafiles\prod\example01.dbf';

restore database;

release channel c1;

release channel c2;

release channel c3;

release channel c4;

recover database;

10、主備庫添加standby日志(比online log至少多一個)

主庫

alter database add standby logfile thread 1 group 4('C:\app\datafiles\orcl\standby04.log') size 50M;

alter database add standby logfile thread 1 group 5 ('C:\app\datafiles\orcl\standby05.log') size 50M;

alter database add standby logfile thread 1 group 6 ('C:\app\datafiles\orcl\standby06.log') size 50M;

alter database add standby logfile thread 1 group 7 ('C:\app\datafiles\orcl\standby07.log') size 50M;

alter database add standby logfile thread 1 group 8 ('C:\app\datafiles\orcl\standby08.log') size 50M;

備庫

alter database add standby logfile thread 1 group 4('C:\app\datafiles\prod\standby04.log') size 50M;

alter database add standby logfile thread 1 group 5 ('C:\app\datafiles\prod\standby05.log') size 50M;

alter database add standby logfile thread 1 group 6 ('C:\app\datafiles\prod\standby06.log') size 50M;

alter database add standby logfile thread 1 group 7 ('C:\app\datafiles\prod\standby07.log') size 50M;

alter database add standby logfile thread 1 group 8 ('C:\app\datafiles\prod\standby08.log') size 50M;

11、主庫重新開機DB 因為log_archive_config重新開機生效

啟動同步

SQL>alter database recover managed standby database disconnect from session;

SQL> recover managed standby database cancel;

SQL>alter database open read only;

SQL>alter database recover managed standby database using current logfile disconnect from session;

驗證

主庫 v$archived_log

SQL> select thread#,max(sequence#) from v$archived_log where applied='NO' group by thread#;

備庫 v$archived_log

SQL> select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;