本文记录了物理dg的第二种安装方法,使用rman duplicate from active database,不需要做备份文件。
准备工作:
1.两台虚拟机,主机名:n1, n2,操作系统:centos6.7,建好信任关系
2.oracle database 11.2.0.4软件已装好
3.节点1(n1)数据库创建好,db_name=orcl,db_unique_name=dg1,
归档模式(归档目录/oracle/arc/)
4.变量
n1变量: export ORACLE_SID=dg1 export ORACLE_BASE=/oracle/db export ORACLE_HOME=$ORACLE_BASE/ora11g export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib export PATH=$PATH:$ORACLE_HOME/bin n2变量: export ORACLE_SID=dg2 export ORACLE_BASE=/oracle/db export ORACLE_HOME=$ORACLE_BASE/ora11g export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib export PATH=$PATH:$ORACLE_HOME/bin
5.tns文件内容($ORACLE_BASE/network/admin),n1、n2都需要
# tnsnames.ora Network Configuration File: /oracle/db/ora11g/network/admin/tnsnames.ora # Generated by Oracle configuration tools. dg1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = n1)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dg1) ) ) dg2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = n2)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dg2) ) )
6.静态listener($ORACLE_BASE/network/admin/listener.ora),主备库最好都设置
n1:
# listener.ora Network Configuration File: /oracle/db/ora11g/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = dg1) (ORACLE_HOME = /oracle/db/ora11g) (SID_NAME = dg1) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = n1)(PORT = 1521)) )
n2:
# listener.ora Network Configuration File: /oracle/db/ora11g/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = dg2) (ORACLE_HOME = /oracle/db/ora11g) (SID_NAME = dg2) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = n2)(PORT = 1521)) )
1.主库创建pfile
create pfile='/tmp/init.ora' from spfile;
2.将上一步生成的pfile及主库的 密码文件 scp 到备库(注意备库上 密码文件 的名称)
scp /tmp/init.ora oracle@n2:/tmp scp $ORACLE_HOME/dbs/orapwdg1 oracle@n2:$ORACLE_HOME/dbs/orapwdg2
3.备库创建spfile
create spfile from pfile='/tmp/init.ora';
4.备库启动到nomount
startup nomount
5.备库修改参数,并重启到nomount
alter system set db_unique_name=dg2 scope=spfile; alter system set log_archive_config='DG_CONFIG=(dg1,dg2)' scope=spfile; alter system set log_archive_dest_1='LOCATION=/oracle/arc/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg2' scope=spfile; alter system set fal_server=dg1 scope=spfile; alter system set fal_client=dg2 scope=spfile; alter system set standby_file_management=auto scope=spfile; alter system set service_names='dg2' scope=spfile;
startup nomount force
6.备库执行rman(rman target sys/sys@dg1 auxiliary sys/sys@dg2)
duplicate target database for standby nofilenamecheck from active database;
7.备库增加standby日志(主库也需要加,如果在duplicate之前主库已经添加了standby,这时备库可能需要删除再重建standby)
alter database add standby logfile group 4 ('/oracle/db/oradata/orcl/sredo41.log','/oracle/db/oradata/orcl/sredo42.log') size 50M; alter database add standby logfile group 5 ('/oracle/db/oradata/orcl/sredo51.log','/oracle/db/oradata/orcl/sredo52.log') size 50M; alter database add standby logfile group 6 ('/oracle/db/oradata/orcl/sredo61.log','/oracle/db/oradata/orcl/sredo62.log') size 50M;
8.dg创建完成,检查是否正常(检查方法参见 oracle物理dg安装:方法一)
注:
可能会出现的错误
1.备库启动到nomount
--db_recovery_file_dest参数对应的目录(/oracle/db/fast_recovery_area,具体值查看/tmp/init.ora文件)没有创建会报以下错,需要手动创建
SQL> startup nomount ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated ORA-01262: Stat failed on a file destination directory Linux-x86_64 Error: 2: No such file or directory SQL> host [oracle@n2 tmp]$ mkdir -p /oracle/db/fast_recovery_area [oracle@n2 tmp]$ exit exit --audit_file_dest参数对应的目录(/oracle/db/admin/orcl/adump,具体值查看/tmp/init.ora文件)没有创建会报以下错,需要手动创建(创建后需要退出sqlplus重新登录) SQL> startup nomount ORA-09925: Unable to create audit trail file Linux-x86_64 Error: 2: No such file or directory Additional information: 9925 SQL> host [oracle@n2 tmp]$ mkdir -p /oracle/db/admin/orcl/adump [oracle@n2 tmp]$ exit exit SQL> select status from v$instance; select status from v$instance * ERROR at line 1: ORA-01012: not logged on Process ID: 0 Session ID: 0 Serial number: 0 SQL> startup nomount ORA-01012: not logged on SQL> exit Disconnected [oracle@n2 tmp]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Apr 12 13:47:34 2016 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select status from v$instance; STATUS ------------------------------------ STARTED SQL> shutdown immediate ORA-01507: database not mounted ORACLE instance shut down. SQL> startup nomount ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2257880 bytes Variable Size 545262632 bytes Database Buffers 289406976 bytes Redo Buffers 2355200 bytes
2.备库执行rman(rman target sys/sys@dg1 auxiliary sys/sys@dg2)
--控制文件,数据文件 所在目录要存在,否则备库duplicate会报错,手动创建好对应目录,重新执行duplicate继续进行
contents of Memory Script:
{ backup as copy current controlfile for standby auxiliary format '/oracle/db/oradata/orcl/control01.ctl'; restore clone controlfile to '/oracle/db/oradata/orcl/control02.ctl' from '/oracle/db/oradata/orcl/control01.ctl'; } executing Memory Script Starting backup at 11-APR-16 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of Duplicate Db command at 04/11/2016 18:41:11 RMAN-05501: aborting duplication of target database RMAN-03015: error occurred in stored script Memory Script RMAN-03009: failure of backup command on ORA_DISK_1 channel at 04/11/2016 18:41:11 ORA-17628: Oracle error 19505 returned by remote Oracle server
3.备库执行rman(rman target sys/sys@dg1 auxiliary sys/sys@dg2)
--主库rman检查是不是有expired的归档日志等,有的话需要先crosscheck、delete掉(然后备库要退出rman重新登,再执行duplicate),否则备库dupliate会报错 Starting backup at 11-APR-16 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/oracle/db/ora11g/dbs/snapcf_dg1.f tag=TAG20160411T184405 RECID=11 STAMP=908909046 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 11-APR-16 Starting restore at 11-APR-16 using channel ORA_AUX_DISK_1 DBGSQL: TARGET> begin :fhdbi := dbms_rcvcat.getDbid; end; DBGSQL: sqlcode = 6550 DBGSQL: B :fhdbi = 32767 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of Duplicate Db command at 04/11/2016 18:44:06 RMAN-05501: aborting duplication of target database RMAN-03015: error occurred in stored script Memory Script ORA-06550: line 1, column 17: PLS-00201: identifier 'DBMS_RCVCAT.GETDBID' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored
检查及删除过期expired日志的命令
crosscheck archivelog all;
list expired archivelog all;
delete expired archivelog all;