1.環境:
a.主機環境:centos6.5
b.軟件環境:oracle 11.2.0.4
c.主機信息:
DG1:192.168.100.51(數據庫sid:atest)
DG2:192.168.100.52
2.前提工作(主從都要設置):
a.關閉防火牆:/etc/init.d/iptables stop
b.關閉selinux:setenforce 0
查看狀態:getenforce(關閉狀態:Permissive)
3.3.主庫設置:
a.設置主庫db_unique_name:
alter system set db_unique_name='patest' scope=spfile;
b.設置主庫為強制記錄日志:
alter database force logging;
檢查狀態(YEs為強制):
select name,force_logging from v$database;
c.設置standy_file_management:
alter system set standby_file_management ='AUTO';
d.創建standbylog:
alter database add standby logfile group 11 '/u01/app/oracle/oradata/ATEST/standbylog/standby11.log' size 50m;
alter database add standby logfile group 12 '/u01/app/oracle/oradata/ATEST/standbylog/standby12.log' size 50m;
alter database add standby logfile group 13 '/u01/app/oracle/oradata/ATEST/standbylog/standby13.log' size 50m;
alter database add standby logfile group 14 '/u01/app/oracle/oradata/ATEST/standbylog/standby14.log' size 50m;
e.開啟歸檔(簡單不詳述):
alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/ATEST/archivelog'; alter database archivelog;
f.開啟DGbroker:
alter system set DG_BROKER_START=TRUE;
g.傳輸pfile和密碼文件:
create pfile from spfile; scp initatest.ora orapwatest 192.168.100.52:/u01/app/oracle/product/11.2.0/db1/dbs/
h.設置監聽:atest,patest,patest_DGMGRL
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = atest) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1) (SID_NAME = atest) ) (SID_DESC = (GLOBAL_DBNAME = patest) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1) (SID_NAME = atest) ) (SID_DESC = (GLOBAL_DBNAME = patest_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1) (SID_NAME = atest) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = vijay01.database.com)(PORT = 1521)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
i.設置tnsnames.ora
ATEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.51)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atest) ) ) PATEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.51)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atest) ) ) SATEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.52)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atest) ) )
4.備庫設置:
a.設置監聽:atest,satest,satest_DGMGRL
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = atest) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1) (SID_NAME = atest) ) (SID_DESC = (GLOBAL_DBNAME = satest) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1) (SID_NAME = atest) ) (SID_DESC = (GLOBAL_DBNAME = satest_DGMGRL) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1) (SID_NAME = atest) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = vijay02.database.com)(PORT = 1521)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
b.設置tnsnames.ora
ATEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.52)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atest) ) ) SATEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.52)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atest) ) ) PATEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.51)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = atest) ) )
5.備份主庫:
a.rman target /
b.backup database;
6.在備庫上克隆主庫:
a.修改備庫pfile上的db_unique_name=satest
b.啟動數據庫到nomount:
startup nomount
c.登陸rman:
rman target sys/123456@patest auxiliary sys/123456@satest
d.開始克隆:
duplicate target database for standby nofilenamecheck from active database;
7.設置DGbroker:
a.登陸dgmgrl:
dgmgrl sys/123456@patest
b.設置主庫:
create configuration dgc as primary database is patest connect identifier is patest;
c.添加備庫:
add database satest as connect identifier is satest maintained as physical;
d.啟用配置文件:
enable configuration
e.查看DGbroker配置:
show configuration [verbose]; show database [verbose] 'satest';
show database 'patest''StatusReport';
f.查看數據庫的DG狀態:
SELECT GROUP#,dbid,archived,status from v$standby_log; select dest_id,valid_type,valid_role,valid_now from v$archive_dest; select process,status,group#,thread#,sequence# from v$managed_standby order by process,group#,thread#,sequence#; select name,value,time_computed from v$dataguard_stats; select timestamp,facility,dest_id,message_num,error_code,message from v$dataguard_status order by timestamp; select recid,archived,applied from v$archived_log;
8.DG不同步檢查步驟:
1.檢查密碼文件 2.檢查網絡 3.檢查參數文件 4.檢查防火牆或selinux 5.如以上均無問題,只能說明dg環境有問題,需要重新搭建dg(重新傳輸數據文件到主庫,在重新同步)