一、主库打开forcelogging
startup mount;
alter database force logging;
二、主 备 库配置监听
主:listener.oraSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = primary) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = primary) )) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521)) ) ) 备:listener.oraSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = standby) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = standby) )) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521)) ) ) 主、备:tnsnames.oraPRIMARY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = primary) ) ) STANDBY = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1522)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = standby) ) )
三、主库配置DG参数
配置spfile信息
alter system set db_name='primary' scope=spfile;
-- 主备db_name必须一致;
alter system set db_unique_name='primary' scope=spfile;
alter system set log_archive_config='DG_CONFIG=(primary,standby)' scope=spfile;
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/fast_recovery_area valid_for=(all_logfiles,all_roles) db_unique_name=primary' scope=spfile;
alter system set log_archive_dest_2='SERVICE=standby lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=standby' scope=spfile;
--注意每一个=前后均不能有空格,否则报错;
alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
alter system set standby_file_management=AUTO scope=spfile;
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;
alter system set fal_server=primary scope=spfile;--11g中fal参数已被废除,fal-fetch archivelog 进程,一般情况下看不到此进程;
alter system set fal_client=standby scope=spfile;
shutdown abort;
startup;
四、主 备 库创建密码文件【一 至 四 保证主库处于mount或者以下】
orapwd file=orapw$ORACLE_SID password=redhat entries=5 --主库orapwd file=orapw$ORACLE_SID password=redhat entries=5 --备库
五、主库手动创建pfile并传到备库
create pfile='/tmp/initstandby.ora' from spfile;
scp -r $ORACLE_BASE/admin/ $ORACLE_BASE/diag/ $ORACLE_BASE/oradata/ $ORACLE_BASE/fast_recovery_area/ standby:/$ORACLE_BASE
六、复制数据文件到备库
scp -r $ORACLE_BASE/admin/ $ORACLE_BASE/diag/ $ORACLE_BASE/oradata/ $ORACLE_BASE/fast_recovery_area/ standby:/$ORACLE_BASE
说明:其实传过去的数据,备库并不使用。备库使用的是主库的目录!
七、利用指定的pfile复制出来的spfile打开备库到nomount状态
create spfile from pfile='$ORACLE_HOME/dbs/initstandby.ora'startup nomount;
八、备库创建相关配置参数
备库配置
利用主库传过来的pfile启动到nomount状态,并配置如下:
create spfile from pfile='$ORACLE_HOME/dbs/initstandby.ora'
startup nomount;
alter system set db_name=primary scope=spfile;
alter system set db_unique_name=standby scope=spfile;
alter system set log_archive_config='DG_CONFIG=(primary,standby)' scope=spfile;
alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/fast_recovery_area valid_for=(all_logfiles,all_roles) db_unique_name=standby' scope=spfile;
alter system set log_archive_dest_2='SERVICE=primary lgwr sync valid_for=(online_logfiles,primary_role) db_unique_name=primary' scope=spfile;
alter system set standby_file_management=AUTO scope=spfile;
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;
alter system set fal_server=standby scope=spfile;
alter system set fal_client=primary scope=spfile;
shutdown abort;
startup nomount;
create pfile from spfile;
九、主库利用rman duplicate 创建备库
rman target sys/redhat@primary auxiliary sys/redhat@standby nocatalogduplicate target database for standby from active database nofilenamecheck;
十、查看备库并open备库
--备库创建后会自动mount
alter database open;
十一、主 备 库增加 standby 日志
a.先查看本地log大小以及路径 select a.bytes,a.members,b.status,b.member from v$log a,v$logfile b where a.group#=b.group#; b.在primary/standby创建4组standby logalter database add standby logfile group 4 '/u01/app/oracle/oradata/primary/redo04.log' size 50m ;alter database add standby logfile group 5 '/u01/app/oracle/oradata/primary/redo05.log' size 50m ;alter database add standby logfile group 6 '/u01/app/oracle/oradata/primary/redo06.log' size 50m;alter database add standby logfile group 7 '/u01/app/oracle/oradata/primary/redo07.log' size 50m;
十二、打开备库实时应用日志,打开flashback功能
recover managed standby database using current logfile disconnect from session;
注意:
主库的flashback on 可以在线打开;
备库的flashback on必须按如下步骤操作:
SQL> select flashback_on from v$database; FLASHBACK_ON------------------NO SQL> alter database recover managed standby database cancel; Database altered. SQL> alter database flashback on; Database altered. SQL> alter database recover managed standby database disconnect from session; Database altered. SQL> select flashback_on from v$database; FLASHBACK_ON------------------YES
十三、相关测试
创建表空间以及相关数据,发现备库秒看
至此11g物理DG配置完毕!