Oracle12c Data Guard搭建手册
注:本文来源: 红黑联盟 《 》
12c 的DataGuard 是在CDB 级别进行的,所以我们的配置都是从CDB角度出发。
测试里主备库的CDB名称相同。
1 环境说明
1 OS Version: 2 3 [root@dave etc]# cat /etc/oracle-release 4 5 Oracle Linux Server release 6.3 6 7 [root@dave etc]# uname -r 8 9 2.6.39-200.29.3.el6uek.x86_64 10 11 DB Version: 12 13 > * v$version; 14 15 BANNER CON_ID 16 17 ------------------------------------------------------------------------------------------ 18 19 Oracle 12c Enterprise EditionRelease 12.1.0.1.0 - 64 Production 0 20 21 PL/ Release 12.1.0.1.0 - Production 0 22 23 CORE 12.1.0.1.0 Production 0 24 25 TNS Linux: Version 12.1.0.1.0 -Production 0 26 27 NLSRTL Version 12.1.0.1.0 - Production 0 28 29 30 31 > show pdbs 32 33 34 35 CON_ID CON_NAME MODE RESTRICTED 36 37 ---------- ---------------------------------------- ---------- 38 39 2 PDB$SEED 40 41 3 PCNDBA 42 43 >
实例名:
Database
DB_UNIQUE_NAME
Oracle Net Service Name
Primary
PCNDBA_P
PCNDBA_P
Physical standby
PCNDBA_S
PCNDBA_S
IP 地址:
1 [root@dave network-scripts]# cat /etc/hosts 2 3 127.0.0.1 localhost dave 4 5 192.168.56.3 dg1 6 7 192.168.56.4 dg2 8 9 [root@dave network-scripts]#
这里用主库上的PDB:PCNDBA 做我们的主库。
2 主库启动FORCE LOGGING
1 > name,open_mode v$pdbs; 2 3 4 5 NAME OPEN_MODE 6 7 ------------------------------ ---------- 8 9 PDB$SEED 10 11 PCNDBA 12 13 14 15 > force logging; 16 17 altered. 18 19 20 21 > force_logging fromv$; 22 23 FORCE_LOGGING 24 25 --------------------------------------- 26 27 YES
3 启动归档模式
1 > show con_name 2 3 4 5 CON_NAME 6 7 ------------------------------ 8 9 CDB$ROOT 10 11 > archive log list; 12 13 log mode Archive Mode 14 15 Automatic archival Disabled 16 17 Archive destination USE_DB_RECOVERY_FILE_DEST 18 19 Oldest online log sequence 14 20 21 log sequence 16 22 23 > 24 25 closed. 26 27 dismounted. 28 29 ORACLE instance shut down. 30 31 > startup mount 32 33 ORACLE instance started. 34 35 36 37 Total System Area 1620115456 bytes 38 39 Fixed 2288920 bytes 40 41 Variable 1040188136 bytes 42 43 Buffers 570425344 bytes 44 45 Redo Buffers 7213056 bytes 46 47 mounted. 48 49 > archivelog; 50 51 52 53 altered. 54 55 56 57 >
这里归档直接放在FRA里了:
1 > show parameter recovery 2 3 4 5 NAME TYPE 6 7 ------------------------------------ ----------------------------------------- 8 9 db_recovery_file_dest string /home/ora12c/app/oracle/fast_recovery_area 10 11 db_recovery_file_dest_size big 4800M 12 13 recovery_parallelism 0 14 15 16 17 > system setdb_recovery_file_dest_size=10G; 18 19 System altered. 20 21 22 23 > show parameter recovery 24 25 NAME TYPE 26 27 ----------------------------------------------- ------------------------------ 28 29 db_recovery_file_dest string /home/ora12c/app/oracle/fast_recovery_area 30 31 db_recovery_file_dest_size biginteger 10G 32 33 recovery_parallelism 0 34 35 > 36 37 38 39 > ; 40 41 42 43 altered. 44 45 46 47 > name,open_mode v$pdbs; 48 49 50 51 NAME OPEN_MODE 52 53 ------------------------------ ---------- 54 55 PDB$SEED 56 57 PCNDBA MOUNTED 58 59 60 61 > pluggable pcndbaopen; 62 63 Pluggable altered. 64 65 66 67 > name,open_mode v$pdbs; 68 69 NAME OPEN_MODE 70 71 ------------------------------ ---------- 72 73 PDB$SEED 74 75 PCNDBA
4 在主库添加 standby redo logfile
在Oracle 12c的架构里,online redo log 和控制文件是保存在CDB中的,PDB中只有运行需要的数据文件,所以我们这里加standby redo log,也是在CDB中加。
查看 Primary 库的 REDO 相关信息:
1 > show con_name 2 3 4 5 CON_NAME 6 7 ------------------------------ 8 9 CDB$ROOT 10 11 > #, members, bytes v$log; 12 13 14 15 # MEMBERS BYTES 16 17 ---------- ---------- ---------- 18 19 1 2 52428800 20 21 2 2 52428800 22 23 3 2 52428800 24 25 26 27 > member v$logfile; 28 29 30 31 MEMBER 32 33 ----------------------------------------------------------------------------------------- 34 35 /home/ora12c/app/oracle/oradata/CNDBA/onlinelog/o1_mf_3_9y3rrb3v_.log 36 37 /home/ora12c/app/oracle/fast_recovery_area/CNDBA/onlinelog/o1_mf_3_9y3rrb9n_.log 38 39 /home/ora12c/app/oracle/oradata/CNDBA/onlinelog/o1_mf_2_9y3rr54v_.log 40 41 /home/ora12c/app/oracle/fast_recovery_area/CNDBA/onlinelog/o1_mf_2_9y3rr5b2_.log 42 43 /home/ora12c/app/oracle/oradata/CNDBA/onlinelog/o1_mf_1_9y3rqznr_.log 44 45 /home/ora12c/app/oracle/fast_recovery_area/CNDBA/onlinelog/o1_mf_1_9y3rr09s_
添加 4(3+1)个standby logfile:
1 > standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo01.log' 50M; 2 3 altered. 4 5 6 7 > standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo02.log' 50M; 8 9 altered. 10 11 12 13 > standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo03.log' 50M; 14 15 altered. 16 17 18 19 > standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo04.log' 50M; 20 21 altered.
5 分别在主备库配置监听并启动
1 --这里直接使用netmgr工具生成:注意静态监听注册中配置的pdb。 2 3 [ora12c@dave admin]$ cat listener.ora 4 5 # listener.ora Network Configuration :/home/ora12c/app/oracle/product/12.1.0/db_1/network/admin/listener.ora 6 7 # Generated Oracle configuration tools. 8 9 10 11 SID_LIST_LISTENER = 12 13 (SID_LIST = 14 15 (SID_DESC = 16 17 (GLOBAL_DBNAME = cndba) 18 19 (ORACLE_HOME = /home/ora12c/app/oracle/product/12.1.0/db_1) 20 21 (SID_NAME = cndba) 22 23 ) 24 25 ) 26 27 28 29 LISTENER = 30 31 (DESCRIPTION_LIST = 32 33 (DESCRIPTION = 34 35 (ADDRESS = (PROTOCOL = IPC)( = EXTPROC1521)) 36 37 ) 38 39 (DESCRIPTION = 40 41 (ADDRESS = (PROTOCOL = TCP)(HOST = dave)(PORT = 1521)) 42 43 ) 44 45 ) 46 47 48 49 ADR_BASE_LISTENER = /home/ora12c/app/oracle 50 51 52 53 [ora12c@dave admin]$ lsnrctl reload 54 55 56 57 LSNRCTL Linux: Version 12.1.0.1.0 -Production 06-AUG-2014 19:26:50 58 59 60 61 Copyright (c) 1991, 2013, Oracle. rights reserved. 62 63 64 65 Connecting (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(=EXTPROC1521))) 66 67 The command completed successfully
6 分别在主备库配置tnsnames.ora
1 [ora12c@dave admin]$ cat tnsnames.ora 2 3 # tnsnames.ora Network Configuration : /home/ora12c/app/oracle/product/12.1.0/db_1/network/admin/tnsnames.ora 4 5 # Generated Oracle configuration tools. 6 7 8 9 CNDBA_S = 10 11 (DESCRIPTION = 12 13 (ADDRESS_LIST = 14 15 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.4)(PORT = 1521)) 16 17 ) 18 19 (CONNECT_DATA = 20 21 (SERVICE_NAME = cndba) 22 23 ) 24 25 ) 26 27 28 29 CNDBA_P = 30 31 (DESCRIPTION = 32 33 (ADDRESS_LIST = 34 35 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.3)(PORT = 1521)) 36 37 ) 38 39 (CONNECT_DATA = 40 41 (SERVICE_NAME = cndba) 42 43 ) 44 45 ) 46 47 48 49 [ora12c@dave admin]$ tnsping cndba_s 50 51 [ora12c@dave admin]$ tnsping cndba_p
7 在备库创建必要的目录
可以参考主库的pfile中的路径:
1 [ora12c@dave admin]$ mkdir -p /home/ora12c/app/oracle/fast_recovery_area 2 3 [ora12c@dave admin]$ mkdir -p/home/ora12c/app/oracle/oradata 4 5 [ora12c@dave admin]$ mkdir -p/home/ora12c/app/oracle/admin/cndba/adump
8 在主库创建pfile 文件并修改pfile 内容
1 > pfile spfile; 2 3 created.
在pfile中添加如下内容:
1 # dg 2 3 *.db_name='cndba' 4 5 *.db_unique_name='cndba_p' 6 7 *.log_archive_config='dg_config=(cndba_p,cndba_s)' 8 9 *.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DESTvalid_for=(all_logfiles,all_roles) db_unique_name=cndba_p' 10 11 *.log_archive_dest_2='service=cndba_s valid_for=(online_logfiles,primary_role) lgwr affirmsync db_unique_name=cndba_s' 12 13 *.log_archive_dest_state_1=enable 14 15 *.log_archive_dest_state_2=enable 16 17 *.standby_file_management='auto' 18 19 *.fal_server='cndba_s'
如果主备库CDB名称不同,还需要加如下参数:
1 *.DB_FILE_NAME_CONVERT='cndba','dave' 2 3 *.LOG_FILE_NAME_CONVERT='cndba','dave'
用新参数重启数据库:
1 > 2 3 closed. 4 5 dismounted. 6 7 ORACLE instance shut down. 8 9 10 11 > spfile pfile; 12 13 created. 14 15 16 17 > startup 18 19 ORACLE instance started. 20 21 22 23 Total System Area 1620115456 bytes 24 25 Fixed 2288920 bytes 26 27 Variable 1040188136 bytes 28 29 Buffers 570425344 bytes 30 31 Redo Buffers 7213056 bytes 32 33 mounted. 34 35 opened. 36 37 > 38 9 将主库的口
9 将主库的口令文件copy到备库
我这里主备库的CDB实例相同,如果不同,可以使用orapwd命令重建。
1 [ora12c@dave dbs]$ scp orapwcndba192.168.56.4:`pwd` 2 3 ora12c@192.168.56.4's password: 4 5 orapwcndba 100% 7680 7.5KB/s 00:00 6 7 [ora12c@dave dbs]$
10 将主库的参数文件copy到备库并修改
1 [ora12c@dave dbs]$ scp initcndba.ora192.168.56.4:`pwd` 2 3 ora12c@192.168.56.4's password: 4 5 initcndba.ora 100% 1593 1.6KB/s 00:00 6 7 [ora12c@dave dbs]$ 8 9 10 11 修改如下内容,在重新生成spfile: 12 13 # standby dg 14 15 *.db_unique_name='cndba_s' 16 17 *.log_archive_config='dg_config=(cndba_p,cndba_s)' 18 19 *.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DESTvalid_for=(all_logfiles,all_roles) db_unique_name=cndba_s' 20 21 *.log_archive_dest_2='service=cndba_pvalid_for=(online_logfiles,primary_role) lgwr affirm sync db_unique_name=cndba_p' 22 23 *.log_archive_dest_state_1=enable 24 25 *.log_archive_dest_state_2=enable 26 27 *.standby_file_management='auto' 28 29 *.fal_server='cndba_p'
注意修改控制文件的路径,也使用新路径。
1 > spfile pfile; 2 3 created.
11 用spfile 将备库启动到nomount 状态
1 > startup nomount 2 3 ORACLE instance started. 4 5 6 7 Total System Area 1620115456 bytes 8 9 Fixed 2288920 bytes 10 11 Variable 1040188136 bytes 12 13 Buffers 570425344 bytes 14 15 Redo Buffers 7213056 bytes 16 17 >
12 开始进行Active duplicate
1 [ora12c@dave network-scripts]$ rman targetsys/oracle@cndba_p auxiliary sys/oracle@cndba_s; 2 3 4 5 Recovery Manager: Release 12.1.0.1.0 -Production Wed Aug 6 20:41:02 2014 6 7 8 9 Copyright (c) 1982, 2013, Oracle / itsaffiliates. rights reserved. 10 11 12 13 connected target : CNDBA(DBID=119362621) 14 15 connected auxiliary : CNDBA (notmounted) 16 17 18 19 20 21 RMAN>duplicatetarget standby active nofilenamecheck dorecover; 22 23 24 25 [ora12c@dave network-scripts]$ rman targetsys/oracle@cndba_p auxiliary sys/oracle@cndba_s; 26 27 28 29 Recovery Manager: Release 12.1.0.1.0 -Production Wed Aug 6 20:41:02 2014 30 31 32 33 Copyright (c) 1982, 2013, Oracle / itsaffiliates. rights reserved. 34 35 36 37 connected target : CNDBA(DBID=119362621) 38 39 connected auxiliary : CNDBA (notmounted) 40 41 42 43 RMAN> duplicate target forstandby active nofilenamecheck dorecover; 44 45 46 47 Starting Duplicate Db 06-AUG-14 48 49 target control insteadof recovery 50 51 allocated channel: ORA_AUX_DISK_1 52 53 channel ORA_AUX_DISK_1: SID=21 devicetype= 54 55 log archived 56 57 58 59 contents Memory Script: 60 61 { 62 63 copy reuse 64 65 targetfile '/home/ora12c/app/oracle/product/12.1.0/db_1/dbs/orapwcndba' auxiliaryformat 66 67 '/home/ora12c/app/oracle/product/12.1.0/db_1/dbs/orapwcndba' ; 68 69 } 70 71 executing Memory Script 72 73 74 75 Starting 06-AUG-14 76 77 allocated channel: ORA_DISK_1 78 79 channel ORA_DISK_1: SID=48 device type= 80 81 Finished 06-AUG-14 82 83 84 85 contents Memory Script: 86 87 { 88 89 clone "alter system set control_files = 90 91 ''/home/ora12c/app/oracle/oradata/CNDBA/controlfile/o1_mf_9y3rqtn9_.ctl'',''/home/ora12c/app/oracle/fast_recovery_area/CNDBA/controlfile/o1_mf_9y3rqvky_.ctl''comment= 92 93 ''Set RMAN'' scope=spfile"; 94 95 clone service 'cndba_p' standby controlfile; 96 97 } 98 99 executing Memory Script100 101 102 103 statement: system control_files = ''/home/ora12c/app/oracle/oradata/CNDBA/controlfile/o1_mf_9y3rqtn9_.ctl'',''/home/ora12c/app/oracle/fast_recovery_area/CNDBA/controlfile/o1_mf_9y3rqvky_.ctl''comment= ''Set RMAN'' scope=spfile104 105 106 107 Starting 06-AUG-14108 109 channel ORA_AUX_DISK_1110 111 112 113 channel ORA_AUX_DISK_1: starting datafilebackup 114 115 channel ORA_AUX_DISK_1: networkbackup service cndba_p116 117 channel ORA_AUX_DISK_1: restoring controlfile118 119 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:07120 121 name=/home/ora12c/app/oracle/oradata/CNDBA/controlfile/o1_mf_9y3rqtn9_.ctl122 123 filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA/controlfile/o1_mf_9y3rqvky_.ctl124 125 Finished 06-AUG-14126 127 128 129 contents Memory Script:130 131 {132 133 clone 'alter database mount standby database';134 135 }136 137 executing Memory Script138 139 140 141 statement: mount standbydatabase142 143 144 145 contents Memory Script:146 147 {148 149 newname clone tempfile 1 new;150 151 newname clone tempfile 2 new;152 153 newname clone tempfile 3 new;154 155 switchclone tempfile ;156 157 newname clone datafile 1 new;158 159 newname clone datafile 3 new;160 161 newname clone datafile 4 new;162 163 newname clone datafile 5 new;164 165 newname clone datafile 6 new;166 167 newname clone datafile 7 new;168 169 newname clone datafile 8 new;170 171 newname clone datafile 9 new;172 173 newname clone datafile 10 new;174 175 176 177 service 'cndba_p' clone 178 179 ;180 181 'alter system archive log current';182 183 }184 185 executing Memory Script186 187 188 189 executing command: NEWNAME190 191 192 193 executing command: NEWNAME194 195 196 197 executing command: NEWNAME198 199 200 201 renamed tempfile 1 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_temp_%u_.tmp controlfile202 203 renamed tempfile 2 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_temp_%u_.tmp controlfile204 205 renamed tempfile 3 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_temp_%u_.tmp controlfile206 207 208 209 executing command: NEWNAME210 211 212 213 executing command: NEWNAME214 215 216 217 executing command: NEWNAME218 219 220 221 executing command: NEWNAME222 223 224 225 executing command: NEWNAME226 227 228 229 executing command: NEWNAME230 231 232 233 executing command: NEWNAME234 235 236 237 executing command: NEWNAME238 239 240 241 executing command: NEWNAME242 243 244 245 Starting 06-AUG-14246 247 channel ORA_AUX_DISK_1248 249 250 251 channel ORA_AUX_DISK_1: starting datafilebackup 252 253 channel ORA_AUX_DISK_1: networkbackup service cndba_p254 255 channel ORA_AUX_DISK_1: specifyingdatafile(s) 256 257 channel ORA_AUX_DISK_1: restoring datafile00001 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_%u_.dbf258 259 channel ORA_AUX_DISK_1: complete,elapsed : 00:01:37260 261 channel ORA_AUX_DISK_1: starting datafilebackup 262 263 channel ORA_AUX_DISK_1: networkbackup service cndba_p264 265 channel ORA_AUX_DISK_1: specifyingdatafile(s) 266 267 channel ORA_AUX_DISK_1: restoring datafile00003 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_%u_.dbf268 269 channel ORA_AUX_DISK_1: complete,elapsed : 00:01:25270 271 channel ORA_AUX_DISK_1: starting datafilebackup 272 273 channel ORA_AUX_DISK_1: networkbackup service cndba_p274 275 channel ORA_AUX_DISK_1: specifying datafile(s) 276 277 channel ORA_AUX_DISK_1: restoring datafile00004 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_undotbs1_%u_.dbf278 279 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:25280 281 channel ORA_AUX_DISK_1: starting datafilebackup 282 283 channel ORA_AUX_DISK_1: networkbackup service cndba_p284 285 channel ORA_AUX_DISK_1: specifyingdatafile(s) 286 287 channel ORA_AUX_DISK_1: restoring datafile00005 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_%u_.dbf288 289 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:35290 291 channel ORA_AUX_DISK_1: starting datafilebackup 292 293 channel ORA_AUX_DISK_1: networkbackup service cndba_p294 295 channel ORA_AUX_DISK_1: specifyingdatafile(s) 296 297 channel ORA_AUX_DISK_1: restoring datafile00006 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_%u_.dbf298 299 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:01300 301 channel ORA_AUX_DISK_1: starting datafilebackup 302 303 channel ORA_AUX_DISK_1: networkbackup service cndba_p304 305 channel ORA_AUX_DISK_1: specifyingdatafile(s) 306 307 channel ORA_AUX_DISK_1: restoring datafile00007 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_%u_.dbf308 309 channel ORA_AUX_DISK_1: complete,elapsed : 00:01:15310 311 channel ORA_AUX_DISK_1: starting datafilebackup 312 313 channel ORA_AUX_DISK_1: networkbackup service cndba_p314 315 channel ORA_AUX_DISK_1: specifyingdatafile(s) 316 317 channel ORA_AUX_DISK_1: restoring datafile00008 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_%u_.dbf318 319 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:35320 321 channel ORA_AUX_DISK_1: starting datafilebackup 322 323 channel ORA_AUX_DISK_1: networkbackup service cndba_p324 325 channel ORA_AUX_DISK_1: specifyingdatafile(s) 326 327 channel ORA_AUX_DISK_1: restoring datafile00009 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_%u_.dbf328 329 channel ORA_AUX_DISK_1: complete,elapsed : 00:01:15330 331 channel ORA_AUX_DISK_1: starting datafilebackup 332 333 channel ORA_AUX_DISK_1: networkbackup service cndba_p334 335 channel ORA_AUX_DISK_1: specifyingdatafile(s) 336 337 channel ORA_AUX_DISK_1: restoring datafile00010 /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_%u_.dbf338 339 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:03340 341 Finished 06-AUG-14342 343 344 345 statement: system archive logcurrent346 347 log archived348 349 350 351 contents Memory Script:352 353 {354 355 clone force service 'cndba_p'356 357 archivelog scn 1922781;358 359 switch clone datafile ;360 361 }362 363 executing Memory Script364 365 366 367 Starting 06-AUG-14368 369 channel ORA_AUX_DISK_1370 371 372 373 channel ORA_AUX_DISK_1: starting archivedlog destination374 375 channel ORA_AUX_DISK_1: networkbackup service cndba_p376 377 channel ORA_AUX_DISK_1: restoring archivedlog378 379 archived log thread=1 sequence=18380 381 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:01382 383 channel ORA_AUX_DISK_1: starting archivedlog destination384 385 channel ORA_AUX_DISK_1: networkbackup service cndba_p386 387 channel ORA_AUX_DISK_1: restoring archivedlog388 389 archived log thread=1 sequence=19390 391 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:02392 393 channel ORA_AUX_DISK_1: starting archivedlog destination394 395 channel ORA_AUX_DISK_1: networkbackup service cndba_p396 397 channel ORA_AUX_DISK_1: restoring archivedlog398 399 archived log thread=1 sequence=20400 401 channel ORA_AUX_DISK_1: complete,elapsed : 00:00:01402 403 Finished 06-AUG-14404 405 406 407 datafile 1 switched datafile copy408 409 datafile copy RECID=12STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_9y48opp7_.dbf410 411 datafile 3 switched datafile copy412 413 datafile copy RECID=13STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_9y48rr3z_.dbf414 415 datafile 4 switched datafile copy416 417 datafile copy RECID=14STAMP=854916586 name=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_undotbs1_9y48vf5v_.dbf418 419 datafile 5 switched datafile copy420 421 datafile copy RECID=15STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_9y48w6bx_.dbf422 423 datafile 6 switched datafile copy424 425 datafile copy RECID=16STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_9y48x8jb_.dbf426 427 datafile 7 switched datafile copy428 429 datafile copy RECID=17STAMP=854916586 name=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_9y48xb36_.dbf430 431 datafile 8 switched datafile copy432 433 datafile copy RECID=18STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_9y48zp0f_.dbf434 435 datafile 9 switched datafile copy436 437 datafile copy RECID=19STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_9y490r5z_.dbf438 439 datafile 10 switched datafile copy440 441 datafile copy RECID=20STAMP=854916586 name=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_9y493301_.dbf442 443 444 445 contents Memory Script:446 447 {448 449 until scn 1923489;450 451 recover452 453 standby454 455 clone 456 457 archivelog458 459 ;460 461 }462 463 executing Memory Script464 465 466 467 executing command: until clause468 469 470 471 Starting recover 06-AUG-14472 473 channel ORA_AUX_DISK_1474 475 476 477 starting media recovery478 479 480 481 archived log thread 1 sequence 18 already /home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_18_9y49378o_.arc482 483 archived log thread 1 sequence 19 already /home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_19_9y49387d_.arc484 485 archived log thread 1 sequence 20 already /home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_20_9y493976_.arc486 487 archived log filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_18_9y49378o_.arcthread=1 sequence=18488 489 archived log filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_19_9y49387d_.arcthread=1 sequence=19490 491 archived log filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_20_9y493976_.arcthread=1 sequence=20492 493 media recovery complete, elapsed :00:00:01494 495 Finished recover 06-AUG-14496 497 Finished Duplicate Db 06-AUG-14498 499 500 501 RMAN>
13 打开备库并并启动apply
duplicate 完成之后,备库是mount的。
1 > open_mode v$; 2 3 4 5 OPEN_MODE 6 7 ---------------------------------------- 8 9 MOUNTED 10 11 12 13 > show pdbs 14 15 16 17 CON_ID CON_NAME MODE RESTRICTED 18 19 ---------- ---------------------------------------- ---------- 20 21 2 PDB$SEED MOUNTED 22 23 3 PCNDBA MOUNTED 24 25 > ; 26 27 28 29 altered. 30 31 32 33 > show pdbs 34 35 36 37 CON_ID CON_NAME MODE RESTRICTED 38 39 ---------- ---------------------------------------- ---------- 40 41 2 PDB$SEED 42 43 3 PCNDBA MOUNTED 44 45 46 47 > pluggable pcndbaopen; 48 49 50 51 Pluggable altered. 52 53 54 55 > show pdbs 56 57 58 59 CON_ID CON_NAME MODE RESTRICTED 60 61 ---------- ---------------------------------------- ---------- 62 63 2 PDB$SEED 64 65 3 PCNDBA
备库是只读的。
1 --查看主库: 2 3 > log_mode,open_mode ,database_role v$; 4 5 6 7 LOG_MODE OPEN_MODE DATABASE_ROLE 8 9 ------------ ------------------------------------ 10 11 ARCHIVELOG 12 13 14 15 --备库: 16 17 > log_mode,open_mode ,database_role v$; 18 19 20 21 LOG_MODE OPEN_MODE DATABASE_ROLE 22 23 ------------ ------------------------------------ 24 25 ARCHIVELOG PHYSICAL STANDBY 26 27 28 29 30 31 --启动real-time apply: 32 33 > recover managedstandby logfile ; 34 35 altered. 36 37 38 39 > open_mode v$; 40 41 42 43 OPEN_MODE 44 45 -------------------- 46 47 APPLY
14 验证DG
1 --在主库创建一个table: 2 3 4 5 > container=pcndba; 6 7 altered. 8 9 10 11 > cndba * fromdba_users; 12 13 cndba * fromdba_users 14 15 * 16 17 ERROR line 1: 18 19 ORA-01109: 20 21 22 23 24 25 > show pdbs 26 27 28 29 CON_ID CON_NAME MODE RESTRICTED 30 31 ---------- ---------------------------------------- ---------- 32 33 3 PCNDBA MOUNTED 34 35 > ; 36 37 altered. 38 39 40 41 > cndba * fromdba_users; 42 43 created. 44 45 46 47 > system switch logfile; 48 49 system switch logfile 50 51 * 52 53 ERROR line 1: 54 55 ORA-65040: operation allowed fromwithin a pluggable
注意:这里可以看到,对于12c的库,日志的切换只能在CDB中进行,也就是我们前面讲的,DG 是在CDB 级别进行的。
1 > system switch logfile; 2 3 System altered.
备库查询:
1 > (1) cndba; 2 3 (1) cndba 4 5 * 6 7 ERROR line 1: 8 9 ORA-00942: does exist
提示表不存在,实际上,我们是在PDB里创建的,切换到对应的PDB下,就可以查询到了:
1 > container=pcndba; 2 3 container=pcndba 4 5 * 6 7 ERROR line 1: 8 9 ORA-00922: missing invalid 10 11 12 13 14 15 > container=pcndba; 16 17 altered. 18 19 20 21 > (1) cndba; 22 23 24 25 (1) 26 27 ---------- 28 29 36