Oracle12c_為RAC配置DATAGUARD
阿新 • • 發佈:2019-01-06
1、主庫環境
以一個節點為例:
OS環境:
[[email protected] ~]# cat /etc/oracle-release
Oracle Linux Server release 6.5
[[email protected] ~]# uname -r
3.8.13-16.2.1.el6uek.x86_64
網路配置:
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost
#public host names
172.26.181.98 rac1
172.26.181.99 rac2
#private host names
192.168.1.1 rac1-priv
192.168.1.2 rac2-priv
#virtual host names
172.26.181.8 rac1-vip
172.26.181.9 rac2-vip
172.26.181.10 cluster-scan
資料庫:
SQL> select * from v$version;
BANNER CON_ID
---------------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
PL/SQL Release 12.1.0.1.0 - Production 0
CORE 12.1.0.1.0 Production 0
TNS for Linux: Version 12.1.0.1.0 - Production 0
NLSRTL Version 12.1.0.1.0 - Production 0
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
2、主庫啟動force logging
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------------------------------
YES
3、主庫開啟歸檔模式
這裡已經處於歸檔模式:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 32
Next log sequence to archive 33
Current log sequence 33
4、在主庫新增standby redo logfile
檢視主庫logfile資訊:
SQL> select group#,thread#,members,bytes from v$log;
GROUP# THREAD# MEMBERS BYTES
---------- ---------- ---------- ----------
1 1 2 52428800
2 1 2 52428800
3 2 2 52428800
4 2 2 52428800
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
+DATA/ORARAC/ONLINELOG/group_2.263.874160233
+FRA/ORARAC/ONLINELOG/group_2.258.874160233
+DATA/ORARAC/ONLINELOG/group_1.262.874160231
+FRA/ORARAC/ONLINELOG/group_1.257.874160231
+DATA/ORARAC/ONLINELOG/group_3.269.874160887
+FRA/ORARAC/ONLINELOG/group_3.259.874160887
+DATA/ORARAC/ONLINELOG/group_4.270.874160889
+FRA/ORARAC/ONLINELOG/group_4.260.874160889
每個例項的group#都加1,因此我們需要建立6個SRL,這裡對SRL不做多路複用:
SQL> alter database add standby logfile thread 1 group 5 '+DATA/ORARAC/ONLINELOG/group_5.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 1 group 6 '+DATA/ORARAC/ONLINELOG/group_6.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 1 group 7 '+DATA/ORARAC/ONLINELOG/group_7.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 2 group 8 '+DATA/ORARAC/ONLINELOG/group_8.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 2 group 9 '+DATA/ORARAC/ONLINELOG/group_9.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 2 group 10 '+DATA/ORARAC/ONLINELOG/group_10.log' size 50m;
Database altered.
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
+DATA/ORARAC/ONLINELOG/group_2.263.874160233
+FRA/ORARAC/ONLINELOG/group_2.258.874160233
+DATA/ORARAC/ONLINELOG/group_1.262.874160231
+FRA/ORARAC/ONLINELOG/group_1.257.874160231
+DATA/ORARAC/ONLINELOG/group_3.269.874160887
+FRA/ORARAC/ONLINELOG/group_3.259.874160887
+DATA/ORARAC/ONLINELOG/group_4.270.874160889
+FRA/ORARAC/ONLINELOG/group_4.260.874160889
+DATA/ORARAC/ONLINELOG/group_5.log
+DATA/ORARAC/ONLINELOG/group_6.log
+DATA/ORARAC/ONLINELOG/group_7.log
MEMBER
--------------------------------------------------------------------------------
+DATA/ORARAC/ONLINELOG/group_8.log
+DATA/ORARAC/ONLINELOG/group_9.log
+DATA/ORARAC/ONLINELOG/group_10.log
14 rows selected.
SQL> select group#,thread# from v$standby_log;
GROUP# THREAD#
---------- ----------
5 1
6 1
7 1
8 2
9 2
10 2
6 rows selected.
5、為備庫配置靜態監聽
備庫上使用netmgr配置靜態監聽(必須為靜態監聽):
[ [email protected] admin]$ more listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome
_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORARACDG)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
(SID_NAME = orarac)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracletest)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
啟動監聽器:
[ [email protected] admin]$ lsnrctl start
注意,通過tnsname連線靜態註冊的nomount狀態的例項時,只能通過sys使用者來連。
6、配置主庫及備庫的tnsnames
RAC的兩個節點和備庫上的檔案都一樣。
tnsnames.ora檔案內容如下:
[[email protected] admin]$ more tnsnames.ora
ORARAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orarac)
)
)
ORARAC1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.8)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orarac1)
)
)
ORARAC2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.9)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orarac2)
)
)
ORARACDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oraracdg)
)
)
7、建立相關目錄
[ [email protected] ~]$ mkdir -p /u01/app/oracle/oradata/oraracdg
[[email protected] ~]$ mkdir -p /u01/app/oracle/admin/oraracdg/adump
[[email protected] oraracdg]$ mkdir -p /u01/app/oracle/oradata/oraracdg/fra
[[email protected] oraracdg]$ mkdir -p /u01/app/oracle/oradata/oraracdg/datafile2
[[email protected] oraracdg]$ mkdir -p /u01/app/oracle/oradata/oraracdg/datafile3
因為oracle12c的資料檔案(CDB,PDB與seed)分別放在不同的目錄(CDB,PDB與seed),所以這裡建立多個目錄放置資料檔案。
8、修改主庫引數檔案內容
建立PFILE:
SQL> create pfile='/home/oracle/pfileorarac.ora' from spfile;
File created.
修改pfile內容:
加上下面的行:
*.db_name='orarac'
*.db_unique_name='orarac'
*.log_archive_config='dg_config=(orarac,oraracdg)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=orarac'
*.log_archive_dest_2='service=oraracdg valid_for=(online_logfiles,primary_role) async db_unique_name=oraracdg'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
#用於角色轉換
*.FAL_SERVER=ORARACDG
*.FAL_CLIENT=ORARAC
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/oraracdg','+DATA/ORARAC/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile2','+DATA/ORARAC/DD7C48AA5A4404A2E04325AAE80A403C/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile3','+DATA/ORARAC/111287D3DD272EB4E05362B51AAC7F13/DATAFILE'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/oraracdg','+DATA/ORARAC/ONLINELOG','/u01/app/oracle/oradata/oraracdg/fra','+FRA/ORARAC/ONLINELOG'
重建spfile:
SQL> create spfile from pfile='/home/oracle/pfileorarac.ora';
File created.
重新以新的spfile啟動rac例項:
[[email protected] ~]$ srvctl stop instance -d orarac -i orarac1,orarac2
[[email protected] ~]$ srvctl start instance -d orarac -i orarac1,orarac2
這樣主庫的引數檔案修改完成。
9、在備庫建立口令檔案
拷貝主庫口令檔案到備庫(注意12cRAC的口令檔案在ASM上)。
10、為備庫設定引數檔案
同樣在主庫生成pfile,然後拷貝到從庫,再在從庫上修改後的內容:
#orarac1.__data_transfer_cache_size=0
#orarac2.__data_transfer_cache_size=0
#orarac2.__db_cache_size=8321499136
#orarac1.__db_cache_size=8321499136
#orarac1.__java_pool_size=67108864
#orarac2.__java_pool_size=67108864
#orarac2.__large_pool_size=100663296
#orarac1.__large_pool_size=100663296
#orarac1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
#orarac2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
#orarac1.__pga_aggregate_target=3388997632
#orarac2.__pga_aggregate_target=3388997632
#orarac1.__sga_target=10099884032
#orarac2.__sga_target=10099884032
#orarac1.__shared_io_pool_size=0
#orarac2.__shared_io_pool_size=0
#orarac1.__shared_pool_size=1543503872
#orarac2.__shared_pool_size=1543503872
#orarac1.__streams_pool_size=0
#orarac2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/oraracdg/adump'
*.audit_trail='db'
#*.cluster_database=true
*.compatible='12.1.0.0.0'
*.control_files='/u01/app/oracle/oradata/oraracdg/control01.ctl'
*.db_block_size=8192
#*.db_create_file_dest='+DATA'
*.db_domain=''
#注意這裡在引數檔案中設定了FILE_NAME_CONVERT那麼在duplicate語句中就應該寫NOFILENAMECHECK子句。
*.DB_FILE_NAME_CONVERT='+DATA/ORARAC/DATAFILE','/u01/app/oracle/oradata/oraracdg','+DATA/ORARAC/DD7C48AA5A4404A2E04325AAE80A403C/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile2','+DATA/ORARAC/111287D3DD272EB4E05362B51AAC7F13/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile3'
*.db_name='orarac'
#注意這裡還指定了閃回恢復區
*.db_recovery_file_dest='/u01/app/oracle/oradata/oraracdg/fra'
*.db_recovery_file_dest_size=5737418240
*.db_unique_name='oraracdg'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=oraracXDB)'
*.enable_pluggable_database=true
*.FAL_CLIENT='ORARACDG'
*.FAL_SERVER='ORARAC'
#orarac1.instance_number=1
#orarac2.instance_number=2
*.log_archive_config='dg_config=(orarac,oraracdg)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=oraracdg'
*.log_archive_dest_2='service=oraracdg valid_for=(online_logfiles,primary_role) async db_unique_name=orarac'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_format='%t_%s_%r.dbf'
*.LOG_FILE_NAME_CONVERT='+DATA/ORARAC/ONLINELOG','/u01/app/oracle/oradata/oraracdg','+FRA/ORARAC/ONLINELOG','/u01/app/oracle/oradata/oraracdg/fra'
*.open_cursors=300
*.pga_aggregate_target=3210m
*.processes=300
*.remote_login_passwordfile='exclusive'
*.sga_target=9630m
*.standby_file_management='auto'
#orarac2.thread=2
#orarac1.thread=1
#orarac1.undo_tablespace='UNDOTBS1'
#orarac2.undo_tablespace='UNDOTBS2'
*.undo_tablespace='UNDOTBS1'
確認pfile已經拷貝到下列目錄:
[[email protected] dbs]$ pwd
/u01/app/oracle/product/12.1.0/dbhome_1/dbs
[[email protected] dbs]$ ll
total 12
-rw-r--r-- 1 oracle oinstall 2539 Mar 25 16:13 initorarac.ora
-rw-r----- 1 oracle oinstall 7680 Mar 25 15:46 orapworarac
以pfile啟動備庫並生成spfile:
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1.0055E+10 bytes
Fixed Size 2691952 bytes
Variable Size 1778388112 bytes
Database Buffers 8254390272 bytes
Redo Buffers 19312640 bytes
再次使用spfile重新啟動備庫:
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1.0055E+10 bytes
Fixed Size 2691952 bytes
Variable Size 1778388112 bytes
Database Buffers 8254390272 bytes
Redo Buffers 19312640 bytes
11、開始duplicate
注意:下面的rman連線句指定了sys使用者和相同的密碼。
[[email protected] admin]$ rman target sys/[email protected] auxiliary sys/[email protected]
Recovery Manager: Release 12.1.0.1.0 - Production on Thu Mar 26 14:13:15 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORARAC (DBID=377624869)
connected to auxiliary database: ORARAC (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;
Starting Duplicate Db at 26-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=414 device type=DISK
current log archived
contents of Memory Script:
{
backup as copy reuse
targetfile '+DATA/orarac/orapworarac' auxiliary format
'/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapworarac' ;
}
executing Memory Script
Starting backup at 26-MAR-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=247 instance=orarac1 device type=DISK
Finished backup at 26-MAR-15
contents of Memory Script:
{
restore clone from service 'orarac' standby controlfile;
}
executing Memory Script
Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/oraracdg/control01.ctl
Finished restore at 26-MAR-15
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.
contents of Memory Script:
{
set newname for tempfile 1 to
"+DATA";
set newname for tempfile 2 to
"/u01/app/oracle/oradata/oraracdg/datafile2/pdbseed_temp01.dbf";
set newname for tempfile 3 to
"+DATA";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/oraracdg/system.258.874160123";
set newname for datafile 3 to
"/u01/app/oracle/oradata/oraracdg/sysaux.257.874160067";
set newname for datafile 4 to
"/u01/app/oracle/oradata/oraracdg/undotbs1.260.874160189";
set newname for datafile 5 to
"/u01/app/oracle/oradata/oraracdg/datafile2/system.266.874160245";
set newname for datafile 6 to
"/u01/app/oracle/oradata/oraracdg/users.259.874160187";
set newname for datafile 7 to
"/u01/app/oracle/oradata/oraracdg/datafile2/sysaux.265.874160245";
set newname for datafile 8 to
"/u01/app/oracle/oradata/oraracdg/undotbs2.268.874160743";
set newname for datafile 9 to
"/u01/app/oracle/oradata/oraracdg/datafile3/system.272.874161075";
set newname for datafile 10 to
"/u01/app/oracle/oradata/oraracdg/datafile3/sysaux.273.874161075";
set newname for datafile 11 to
"/u01/app/oracle/oradata/oraracdg/datafile3/users.275.874161105";
restore
from service 'orarac' clone database
;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to +DATA in control file
renamed tempfile 2 to /u01/app/oracle/oradata/oraracdg/datafile2/pdbseed_temp01.dbf in control file
renamed tempfile 3 to +DATA in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/oraracdg/system.258.874160123
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/oraracdg/sysaux.257.874160067
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/oraracdg/undotbs1.260.874160189
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/oraracdg/datafile2/system.266.874160245
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/oraracdg/users.259.874160187
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/oraracdg/datafile2/sysaux.265.874160245
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/oraracdg/undotbs2.268.874160743
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/oraracdg/datafile3/system.272.874161075
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/oraracdg/datafile3/sysaux.273.874161075
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/oraracdg/datafile3/users.275.874161105
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 26-MAR-15
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'orarac'
archivelog from scn 3855569;
switch clone datafile all;
}
executing Memory Script
Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=103
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=104
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=105
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=71
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=72
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=73
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=74
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 26-MAR-15
datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/system.258.874160123
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/sysaux.257.874160067
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/undotbs1.260.874160189
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile2/system.266.874160245
datafile 6 switched to datafile copy
input datafile copy RECID=7 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/users.259.874160187
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile2/sysaux.265.874160245
datafile 8 switched to datafile copy
input datafile copy RECID=9 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/undotbs2.268.874160743
datafile 9 switched to datafile copy
input datafile copy RECID=10 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile3/system.272.874161075
datafile 10 switched to datafile copy
input datafile copy RECID=11 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile3/sysaux.273.874161075
datafile 11 switched to datafile copy
input datafile copy RECID=12 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile3/users.275.874161105
contents of Memory Script:
{
set until scn 3855975;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 26-MAR-15
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 103 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_103_bk79gson_.arc
archived log for thread 1 with sequence 104 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_104_bk79gtqk_.arc
archived log for thread 1 with sequence 105 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_105_bk79gvso_.arc
archived log for thread 2 with sequence 72 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_72_bk79gxxh_.arc
archived log for thread 2 with sequence 73 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_73_bk79gz01_.arc
archived log for thread 2 with sequence 74 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_74_bk79h024_.arc
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_103_bk79gson_.arc thread=1 sequence=103
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_72_bk79gxxh_.arc thread=2 sequence=72
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_73_bk79gz01_.arc thread=2 sequence=73
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_104_bk79gtqk_.arc thread=1 sequence=104
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_105_bk79gvso_.arc thread=1 sequence=105
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_74_bk79h024_.arc thread=2 sequence=74
media recovery complete, elapsed time: 00:00:00
Finished recover at 26-MAR-15
Finished Duplicate Db at 26-MAR-15
12、開啟備庫並啟動apply
檢視備庫:
[[email protected] admin]$ sqlplus "/as sysdba"
SQL*Plus: Release 12.1.0.1.0 Production on Thu Mar 26 14:25:11 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED MOUNTED
3 TESTPDB MOUNTED
SQL> alter database open;
Database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB MOUNTED
SQL> alter pluggable database testpdb open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ ONLY NO
SQL> select log_mode,open_mode,database_role from v$database;
LOG_MODE OPEN_MODE DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG READ ONLY PHYSICAL STANDBY
檢視主庫:
SQL> select log_mode,open_mode,database_role from v$database;
LOG_MODE OPEN_MODE DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG READ WRITE PRIMARY
在備庫啟動apply:
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
13、驗證
在主庫插入資料:
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
TESTPDB MOUNTED
SQL> alter pluggable database testpdb open;
Pluggable database altered.
SQL> alter session set container=testpdb;
Session altered.
SQL> select * from test.t1;
C1
----------
1
SQL> insert into test.t1 values(2);
1 row created.
SQL> commit;
Commit complete.
在備庫查詢:
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
TESTPDB READ ONLY
SQL> alter session set container=testpdb;
Session altered.
SQL> select * from test.t1;
C1
----------
2
1
OK,在備庫上PDB中的內容也已經插入成功了。
以一個節點為例:
OS環境:
[[email protected] ~]# cat /etc/oracle-release
Oracle Linux Server release 6.5
[[email protected] ~]# uname -r
3.8.13-16.2.1.el6uek.x86_64
網路配置:
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost
#public host names
172.26.181.98 rac1
172.26.181.99 rac2
#private host names
192.168.1.1 rac1-priv
192.168.1.2 rac2-priv
#virtual host names
172.26.181.8 rac1-vip
172.26.181.9 rac2-vip
172.26.181.10 cluster-scan
資料庫:
SQL> select * from v$version;
BANNER CON_ID
---------------------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
PL/SQL Release 12.1.0.1.0 - Production 0
CORE 12.1.0.1.0 Production 0
TNS for Linux: Version 12.1.0.1.0 - Production 0
NLSRTL Version 12.1.0.1.0 - Production 0
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ WRITE NO
2、主庫啟動force logging
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------------------------------
YES
3、主庫開啟歸檔模式
這裡已經處於歸檔模式:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 32
Next log sequence to archive 33
Current log sequence 33
4、在主庫新增standby redo logfile
檢視主庫logfile資訊:
SQL> select group#,thread#,members,bytes from v$log;
GROUP# THREAD# MEMBERS BYTES
---------- ---------- ---------- ----------
1 1 2 52428800
2 1 2 52428800
3 2 2 52428800
4 2 2 52428800
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
+DATA/ORARAC/ONLINELOG/group_2.263.874160233
+FRA/ORARAC/ONLINELOG/group_2.258.874160233
+DATA/ORARAC/ONLINELOG/group_1.262.874160231
+FRA/ORARAC/ONLINELOG/group_1.257.874160231
+DATA/ORARAC/ONLINELOG/group_3.269.874160887
+FRA/ORARAC/ONLINELOG/group_3.259.874160887
+DATA/ORARAC/ONLINELOG/group_4.270.874160889
+FRA/ORARAC/ONLINELOG/group_4.260.874160889
每個例項的group#都加1,因此我們需要建立6個SRL,這裡對SRL不做多路複用:
SQL> alter database add standby logfile thread 1 group 5 '+DATA/ORARAC/ONLINELOG/group_5.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 1 group 6 '+DATA/ORARAC/ONLINELOG/group_6.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 1 group 7 '+DATA/ORARAC/ONLINELOG/group_7.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 2 group 8 '+DATA/ORARAC/ONLINELOG/group_8.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 2 group 9 '+DATA/ORARAC/ONLINELOG/group_9.log' size 50m;
Database altered.
SQL> alter database add standby logfile thread 2 group 10 '+DATA/ORARAC/ONLINELOG/group_10.log' size 50m;
Database altered.
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
+DATA/ORARAC/ONLINELOG/group_2.263.874160233
+FRA/ORARAC/ONLINELOG/group_2.258.874160233
+DATA/ORARAC/ONLINELOG/group_1.262.874160231
+FRA/ORARAC/ONLINELOG/group_1.257.874160231
+DATA/ORARAC/ONLINELOG/group_3.269.874160887
+FRA/ORARAC/ONLINELOG/group_3.259.874160887
+DATA/ORARAC/ONLINELOG/group_4.270.874160889
+FRA/ORARAC/ONLINELOG/group_4.260.874160889
+DATA/ORARAC/ONLINELOG/group_5.log
+DATA/ORARAC/ONLINELOG/group_6.log
+DATA/ORARAC/ONLINELOG/group_7.log
MEMBER
--------------------------------------------------------------------------------
+DATA/ORARAC/ONLINELOG/group_8.log
+DATA/ORARAC/ONLINELOG/group_9.log
+DATA/ORARAC/ONLINELOG/group_10.log
14 rows selected.
SQL> select group#,thread# from v$standby_log;
GROUP# THREAD#
---------- ----------
5 1
6 1
7 1
8 2
9 2
10 2
6 rows selected.
5、為備庫配置靜態監聽
備庫上使用netmgr配置靜態監聽(必須為靜態監聽):
[
# listener.ora Network Configuration File: /u01/app/oracle/product/12.1.0/dbhome
_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORARACDG)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
(SID_NAME = orarac)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracletest)(PORT = 1521))
)
ADR_BASE_LISTENER = /u01/app/oracle
啟動監聽器:
[
注意,通過tnsname連線靜態註冊的nomount狀態的例項時,只能通過sys使用者來連。
6、配置主庫及備庫的tnsnames
RAC的兩個節點和備庫上的檔案都一樣。
tnsnames.ora檔案內容如下:
[[email protected] admin]$ more tnsnames.ora
ORARAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orarac)
)
)
ORARAC1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.8)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orarac1)
)
)
ORARAC2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.9)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orarac2)
)
)
ORARACDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.26.181.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oraracdg)
)
)
7、建立相關目錄
[
[[email protected] ~]$ mkdir -p /u01/app/oracle/admin/oraracdg/adump
[[email protected] oraracdg]$ mkdir -p /u01/app/oracle/oradata/oraracdg/fra
[[email protected] oraracdg]$ mkdir -p /u01/app/oracle/oradata/oraracdg/datafile2
[[email protected] oraracdg]$ mkdir -p /u01/app/oracle/oradata/oraracdg/datafile3
因為oracle12c的資料檔案(CDB,PDB與seed)分別放在不同的目錄(CDB,PDB與seed),所以這裡建立多個目錄放置資料檔案。
8、修改主庫引數檔案內容
建立PFILE:
SQL> create pfile='/home/oracle/pfileorarac.ora' from spfile;
File created.
修改pfile內容:
加上下面的行:
*.db_name='orarac'
*.db_unique_name='orarac'
*.log_archive_config='dg_config=(orarac,oraracdg)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=orarac'
*.log_archive_dest_2='service=oraracdg valid_for=(online_logfiles,primary_role) async db_unique_name=oraracdg'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
#用於角色轉換
*.FAL_SERVER=ORARACDG
*.FAL_CLIENT=ORARAC
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/oraracdg','+DATA/ORARAC/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile2','+DATA/ORARAC/DD7C48AA5A4404A2E04325AAE80A403C/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile3','+DATA/ORARAC/111287D3DD272EB4E05362B51AAC7F13/DATAFILE'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/oraracdg','+DATA/ORARAC/ONLINELOG','/u01/app/oracle/oradata/oraracdg/fra','+FRA/ORARAC/ONLINELOG'
重建spfile:
SQL> create spfile from pfile='/home/oracle/pfileorarac.ora';
File created.
重新以新的spfile啟動rac例項:
[[email protected] ~]$ srvctl stop instance -d orarac -i orarac1,orarac2
[[email protected] ~]$ srvctl start instance -d orarac -i orarac1,orarac2
這樣主庫的引數檔案修改完成。
9、在備庫建立口令檔案
拷貝主庫口令檔案到備庫(注意12cRAC的口令檔案在ASM上)。
10、為備庫設定引數檔案
同樣在主庫生成pfile,然後拷貝到從庫,再在從庫上修改後的內容:
#orarac1.__data_transfer_cache_size=0
#orarac2.__data_transfer_cache_size=0
#orarac2.__db_cache_size=8321499136
#orarac1.__db_cache_size=8321499136
#orarac1.__java_pool_size=67108864
#orarac2.__java_pool_size=67108864
#orarac2.__large_pool_size=100663296
#orarac1.__large_pool_size=100663296
#orarac1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
#orarac2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
#orarac1.__pga_aggregate_target=3388997632
#orarac2.__pga_aggregate_target=3388997632
#orarac1.__sga_target=10099884032
#orarac2.__sga_target=10099884032
#orarac1.__shared_io_pool_size=0
#orarac2.__shared_io_pool_size=0
#orarac1.__shared_pool_size=1543503872
#orarac2.__shared_pool_size=1543503872
#orarac1.__streams_pool_size=0
#orarac2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/oraracdg/adump'
*.audit_trail='db'
#*.cluster_database=true
*.compatible='12.1.0.0.0'
*.control_files='/u01/app/oracle/oradata/oraracdg/control01.ctl'
*.db_block_size=8192
#*.db_create_file_dest='+DATA'
*.db_domain=''
#注意這裡在引數檔案中設定了FILE_NAME_CONVERT那麼在duplicate語句中就應該寫NOFILENAMECHECK子句。
*.DB_FILE_NAME_CONVERT='+DATA/ORARAC/DATAFILE','/u01/app/oracle/oradata/oraracdg','+DATA/ORARAC/DD7C48AA5A4404A2E04325AAE80A403C/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile2','+DATA/ORARAC/111287D3DD272EB4E05362B51AAC7F13/DATAFILE','/u01/app/oracle/oradata/oraracdg/datafile3'
*.db_name='orarac'
#注意這裡還指定了閃回恢復區
*.db_recovery_file_dest='/u01/app/oracle/oradata/oraracdg/fra'
*.db_recovery_file_dest_size=5737418240
*.db_unique_name='oraracdg'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=oraracXDB)'
*.enable_pluggable_database=true
*.FAL_CLIENT='ORARACDG'
*.FAL_SERVER='ORARAC'
#orarac1.instance_number=1
#orarac2.instance_number=2
*.log_archive_config='dg_config=(orarac,oraracdg)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=oraracdg'
*.log_archive_dest_2='service=oraracdg valid_for=(online_logfiles,primary_role) async db_unique_name=orarac'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_format='%t_%s_%r.dbf'
*.LOG_FILE_NAME_CONVERT='+DATA/ORARAC/ONLINELOG','/u01/app/oracle/oradata/oraracdg','+FRA/ORARAC/ONLINELOG','/u01/app/oracle/oradata/oraracdg/fra'
*.open_cursors=300
*.pga_aggregate_target=3210m
*.processes=300
*.remote_login_passwordfile='exclusive'
*.sga_target=9630m
*.standby_file_management='auto'
#orarac2.thread=2
#orarac1.thread=1
#orarac1.undo_tablespace='UNDOTBS1'
#orarac2.undo_tablespace='UNDOTBS2'
*.undo_tablespace='UNDOTBS1'
確認pfile已經拷貝到下列目錄:
[[email protected] dbs]$ pwd
/u01/app/oracle/product/12.1.0/dbhome_1/dbs
[[email protected] dbs]$ ll
total 12
-rw-r--r-- 1 oracle oinstall 2539 Mar 25 16:13 initorarac.ora
-rw-r----- 1 oracle oinstall 7680 Mar 25 15:46 orapworarac
以pfile啟動備庫並生成spfile:
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1.0055E+10 bytes
Fixed Size 2691952 bytes
Variable Size 1778388112 bytes
Database Buffers 8254390272 bytes
Redo Buffers 19312640 bytes
再次使用spfile重新啟動備庫:
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 1.0055E+10 bytes
Fixed Size 2691952 bytes
Variable Size 1778388112 bytes
Database Buffers 8254390272 bytes
Redo Buffers 19312640 bytes
11、開始duplicate
注意:下面的rman連線句指定了sys使用者和相同的密碼。
[[email protected] admin]$ rman target sys/[email protected] auxiliary sys/[email protected]
Recovery Manager: Release 12.1.0.1.0 - Production on Thu Mar 26 14:13:15 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORARAC (DBID=377624869)
connected to auxiliary database: ORARAC (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;
Starting Duplicate Db at 26-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=414 device type=DISK
current log archived
contents of Memory Script:
{
backup as copy reuse
targetfile '+DATA/orarac/orapworarac' auxiliary format
'/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapworarac' ;
}
executing Memory Script
Starting backup at 26-MAR-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=247 instance=orarac1 device type=DISK
Finished backup at 26-MAR-15
contents of Memory Script:
{
restore clone from service 'orarac' standby controlfile;
}
executing Memory Script
Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/oraracdg/control01.ctl
Finished restore at 26-MAR-15
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.
contents of Memory Script:
{
set newname for tempfile 1 to
"+DATA";
set newname for tempfile 2 to
"/u01/app/oracle/oradata/oraracdg/datafile2/pdbseed_temp01.dbf";
set newname for tempfile 3 to
"+DATA";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/oraracdg/system.258.874160123";
set newname for datafile 3 to
"/u01/app/oracle/oradata/oraracdg/sysaux.257.874160067";
set newname for datafile 4 to
"/u01/app/oracle/oradata/oraracdg/undotbs1.260.874160189";
set newname for datafile 5 to
"/u01/app/oracle/oradata/oraracdg/datafile2/system.266.874160245";
set newname for datafile 6 to
"/u01/app/oracle/oradata/oraracdg/users.259.874160187";
set newname for datafile 7 to
"/u01/app/oracle/oradata/oraracdg/datafile2/sysaux.265.874160245";
set newname for datafile 8 to
"/u01/app/oracle/oradata/oraracdg/undotbs2.268.874160743";
set newname for datafile 9 to
"/u01/app/oracle/oradata/oraracdg/datafile3/system.272.874161075";
set newname for datafile 10 to
"/u01/app/oracle/oradata/oraracdg/datafile3/sysaux.273.874161075";
set newname for datafile 11 to
"/u01/app/oracle/oradata/oraracdg/datafile3/users.275.874161105";
restore
from service 'orarac' clone database
;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to +DATA in control file
renamed tempfile 2 to /u01/app/oracle/oradata/oraracdg/datafile2/pdbseed_temp01.dbf in control file
renamed tempfile 3 to +DATA in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/oraracdg/system.258.874160123
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/oraracdg/sysaux.257.874160067
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/oraracdg/undotbs1.260.874160189
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/oraracdg/datafile2/system.266.874160245
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/oraracdg/users.259.874160187
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/oraracdg/datafile2/sysaux.265.874160245
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/oraracdg/undotbs2.268.874160743
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/oraracdg/datafile3/system.272.874161075
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/oraracdg/datafile3/sysaux.273.874161075
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/oraracdg/datafile3/users.275.874161105
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 26-MAR-15
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'orarac'
archivelog from scn 3855569;
switch clone datafile all;
}
executing Memory Script
Starting restore at 26-MAR-15
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=103
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=104
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=105
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=71
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=72
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=73
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service orarac
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=2 sequence=74
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 26-MAR-15
datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/system.258.874160123
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/sysaux.257.874160067
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/undotbs1.260.874160189
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile2/system.266.874160245
datafile 6 switched to datafile copy
input datafile copy RECID=7 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/users.259.874160187
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile2/sysaux.265.874160245
datafile 8 switched to datafile copy
input datafile copy RECID=9 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/undotbs2.268.874160743
datafile 9 switched to datafile copy
input datafile copy RECID=10 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile3/system.272.874161075
datafile 10 switched to datafile copy
input datafile copy RECID=11 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile3/sysaux.273.874161075
datafile 11 switched to datafile copy
input datafile copy RECID=12 STAMP=875370208 file name=/u01/app/oracle/oradata/oraracdg/datafile3/users.275.874161105
contents of Memory Script:
{
set until scn 3855975;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 26-MAR-15
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 103 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_103_bk79gson_.arc
archived log for thread 1 with sequence 104 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_104_bk79gtqk_.arc
archived log for thread 1 with sequence 105 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_105_bk79gvso_.arc
archived log for thread 2 with sequence 72 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_72_bk79gxxh_.arc
archived log for thread 2 with sequence 73 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_73_bk79gz01_.arc
archived log for thread 2 with sequence 74 is already on disk as file /u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_74_bk79h024_.arc
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_103_bk79gson_.arc thread=1 sequence=103
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_72_bk79gxxh_.arc thread=2 sequence=72
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_73_bk79gz01_.arc thread=2 sequence=73
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_104_bk79gtqk_.arc thread=1 sequence=104
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_1_105_bk79gvso_.arc thread=1 sequence=105
archived log file name=/u01/app/oracle/oradata/oraracdg/fra/ORARACDG/archivelog/2015_03_26/o1_mf_2_74_bk79h024_.arc thread=2 sequence=74
media recovery complete, elapsed time: 00:00:00
Finished recover at 26-MAR-15
Finished Duplicate Db at 26-MAR-15
12、開啟備庫並啟動apply
檢視備庫:
[[email protected] admin]$ sqlplus "/as sysdba"
SQL*Plus: Release 12.1.0.1.0 Production on Thu Mar 26 14:25:11 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED MOUNTED
3 TESTPDB MOUNTED
SQL> alter database open;
Database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB MOUNTED
SQL> alter pluggable database testpdb open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 TESTPDB READ ONLY NO
SQL> select log_mode,open_mode,database_role from v$database;
LOG_MODE OPEN_MODE DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG READ ONLY PHYSICAL STANDBY
檢視主庫:
SQL> select log_mode,open_mode,database_role from v$database;
LOG_MODE OPEN_MODE DATABASE_ROLE
------------ -------------------- ----------------
ARCHIVELOG READ WRITE PRIMARY
在備庫啟動apply:
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
13、驗證
在主庫插入資料:
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
TESTPDB MOUNTED
SQL> alter pluggable database testpdb open;
Pluggable database altered.
SQL> alter session set container=testpdb;
Session altered.
SQL> select * from test.t1;
C1
----------
1
SQL> insert into test.t1 values(2);
1 row created.
SQL> commit;
Commit complete.
在備庫查詢:
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
TESTPDB READ ONLY
SQL> alter session set container=testpdb;
Session altered.
SQL> select * from test.t1;
C1
----------
2
1
OK,在備庫上PDB中的內容也已經插入成功了。