本文記錄了物理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;