Oracle 12c 的DataGuard 是在CDB 級別進行的,所以我們的配置都是從CDB角度出發。
測試裡主備庫的數據庫CDB名稱相同。
OS Version: [root@dave etc]# cat /etc/oracle-release Oracle Linux Server release 6.3 [root@dave etc]# uname -r 2.6.39-200.29.3.el6uek.x86_64 DB Version: SQL> select * from v$version; BANNER CON_ID ------------------------------------------------------------------------------------------ Oracle Database 12c Enterprise EditionRelease 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 PCNDBA READ WRITE NO SQL>
實例名:
Database
DB_UNIQUE_NAME
Oracle Net Service Name
Primary
PCNDBA_P
PCNDBA_P
Physical standby
PCNDBA_S
PCNDBA_S
IP 地址:
[root@dave network-scripts]# cat /etc/hosts 127.0.0.1 localhost dave 192.168.56.3 dg1 192.168.56.4 dg2 [root@dave network-scripts]#
這裡用主庫上的PDB:PCNDBA 做我們的主庫。
SQL> select name,open_mode from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY PCNDBA READ WRITE SQL> alter database force logging; Database altered. SQL> select force_logging fromv$database; FORCE_LOGGING --------------------------------------- YES
SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> archive log list; Database log mode No Archive Mode Automatic archival Disabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 14 Current log sequence 16 SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 1620115456 bytes Fixed Size 2288920 bytes Variable Size 1040188136 bytes Database Buffers 570425344 bytes Redo Buffers 7213056 bytes Database mounted. SQL> alter database archivelog; Database altered. SQL>
這裡歸檔直接放在FRA裡了:
SQL> show parameter recovery NAME TYPE VALUE ------------------------------------ ----------------------------------------- db_recovery_file_dest string /home/ora12c/app/oracle/fast_recovery_area db_recovery_file_dest_size big integer 4800M recovery_parallelism integer 0 SQL> alter system setdb_recovery_file_dest_size=10G; System altered. SQL> show parameter recovery NAME TYPE VALUE ----------------------------------------------- ------------------------------ db_recovery_file_dest string /home/ora12c/app/oracle/fast_recovery_area db_recovery_file_dest_size biginteger 10G recovery_parallelism integer 0 SQL> SQL> alter database open; Database altered. SQL> select name,open_mode from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY PCNDBA MOUNTED SQL> alter pluggable database pcndbaopen; Pluggable database altered. SQL> select name,open_mode from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB$SEED READ ONLY PCNDBA READ WRITE
在Oracle 12c的架構裡,online redo log 和控制文件是保存在CDB中的,PDB中只有運行需要的數據文件,所以我們這裡加standby redo log,也是在CDB中加。
查看 Primary 庫的 REDO 相關信息:
SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> select group#, members, bytes from v$log; GROUP# MEMBERS BYTES ---------- ---------- ---------- 1 2 52428800 2 2 52428800 3 2 52428800 SQL> select member from v$logfile; MEMBER ----------------------------------------------------------------------------------------- /home/ora12c/app/oracle/oradata/CNDBA/onlinelog/o1_mf_3_9y3rrb3v_.log /home/ora12c/app/oracle/fast_recovery_area/CNDBA/onlinelog/o1_mf_3_9y3rrb9n_.log /home/ora12c/app/oracle/oradata/CNDBA/onlinelog/o1_mf_2_9y3rr54v_.log /home/ora12c/app/oracle/fast_recovery_area/CNDBA/onlinelog/o1_mf_2_9y3rr5b2_.log /home/ora12c/app/oracle/oradata/CNDBA/onlinelog/o1_mf_1_9y3rqznr_.log /home/ora12c/app/oracle/fast_recovery_area/CNDBA/onlinelog/o1_mf_1_9y3rr09s_.log
添加 4(3+1)個standby logfile:
SQL> alter database add standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo01.log' size 50M; Database altered. SQL> alter database add standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo02.log' size 50M; Database altered. SQL> alter database add standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo03.log' size 50M; Database altered. SQL> alter database add standby logfile '/home/ora12c/app/oracle/oradata/CNDBA/onlinelog/stdredo04.log' size 50M; Database altered.
--這裡直接使用netmgr工具生成:注意靜態監聽注冊中配置的pdb。 [ora12c@dave admin]$ cat listener.ora # listener.ora Network Configuration File:/home/ora12c/app/oracle/product/12.1.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = cndba) (ORACLE_HOME = /home/ora12c/app/oracle/product/12.1.0/db_1) (SID_NAME = cndba) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dave)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /home/ora12c/app/oracle [ora12c@dave admin]$ lsnrctl reload LSNRCTL for Linux: Version 12.1.0.1.0 -Production on 06-AUG-2014 19:26:50 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) The command completed successfully
[ora12c@dave admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /home/ora12c/app/oracle/product/12.1.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. CNDBA_S = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.4)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = cndba) ) ) CNDBA_P = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.3)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = cndba) ) ) [ora12c@dave admin]$ tnsping cndba_s [ora12c@dave admin]$ tnsping cndba_p
可以參考主庫的pfile中的路徑:
[ora12c@dave admin]$ mkdir -p /home/ora12c/app/oracle/fast_recovery_area [ora12c@dave admin]$ mkdir -p/home/ora12c/app/oracle/oradata [ora12c@dave admin]$ mkdir -p/home/ora12c/app/oracle/admin/cndba/adump
SQL> create pfile from spfile; File created.
在pfile中添加如下內容:
#add for primary dg *.db_name='cndba' *.db_unique_name='cndba_p' *.log_archive_config='dg_config=(cndba_p,cndba_s)' *.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DESTvalid_for=(all_logfiles,all_roles) db_unique_name=cndba_p' *.log_archive_dest_2='service=cndba_s valid_for=(online_logfiles,primary_role) lgwr affirmsync db_unique_name=cndba_s' *.log_archive_dest_state_1=enable *.log_archive_dest_state_2=enable *.standby_file_management='auto' *.fal_server='cndba_s'
如果主備庫CDB名稱不同,還需要加如下參數:
*.DB_FILE_NAME_CONVERT='cndba','dave' *.LOG_FILE_NAME_CONVERT='cndba','dave'
用新參數重啟數據庫:
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> create spfile from pfile; File created. SQL> startup ORACLE instance started. Total System Global Area 1620115456 bytes Fixed Size 2288920 bytes Variable Size 1040188136 bytes Database Buffers 570425344 bytes Redo Buffers 7213056 bytes Database mounted. Database opened. SQL>
我這裡主備庫的CDB實例相同,如果不同,可以使用orapwd命令重建。
[ora12c@dave dbs]$ scp orapwcndba192.168.56.4:`pwd` [email protected]'s password: orapwcndba 100% 7680 7.5KB/s 00:00 [ora12c@dave dbs]$
[ora12c@dave dbs]$ scp initcndba.ora192.168.56.4:`pwd` [email protected]'s password: initcndba.ora 100% 1593 1.6KB/s 00:00 [ora12c@dave dbs]$ 修改如下內容,在重新生成spfile: #add for standby dg *.db_unique_name='cndba_s' *.log_archive_config='dg_config=(cndba_p,cndba_s)' *.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DESTvalid_for=(all_logfiles,all_roles) db_unique_name=cndba_s' *.log_archive_dest_2='service=cndba_pvalid_for=(online_logfiles,primary_role) lgwr affirm sync db_unique_name=cndba_p' *.log_archive_dest_state_1=enable *.log_archive_dest_state_2=enable *.standby_file_management='auto' *.fal_server='cndba_p'
注意修改控制文件的路徑,也使用新路徑。
SQL> create spfile from pfile; File created.
SQL> startup nomount ORACLE instance started. Total System Global Area 1620115456 bytes Fixed Size 2288920 bytes Variable Size 1040188136 bytes Database Buffers 570425344 bytes Redo Buffers 7213056 bytes SQL>
[ora12c@dave network-scripts]$ rman targetsys/oracle@cndba_p auxiliary sys/oracle@cndba_s; Recovery Manager: Release 12.1.0.1.0 -Production on Wed Aug 6 20:41:02 2014 Copyright (c) 1982, 2013, Oracle and/or itsaffiliates. All rights reserved. connected to target database: CNDBA(DBID=119362621) connected to auxiliary database: CNDBA (notmounted) RMAN>duplicatetarget database for standby from active database nofilenamecheck dorecover; [ora12c@dave network-scripts]$ rman targetsys/oracle@cndba_p auxiliary sys/oracle@cndba_s; Recovery Manager: Release 12.1.0.1.0 -Production on Wed Aug 6 20:41:02 2014 Copyright (c) 1982, 2013, Oracle and/or itsaffiliates. All rights reserved. connected to target database: CNDBA(DBID=119362621) connected to auxiliary database: CNDBA (notmounted) RMAN> duplicate target database forstandby from active database nofilenamecheck dorecover; Starting Duplicate Db at 06-AUG-14 using target database control file insteadof recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=21 devicetype=DISK current log archived contents of Memory Script: { backup as copy reuse targetfile '/home/ora12c/app/oracle/product/12.1.0/db_1/dbs/orapwcndba' auxiliaryformat '/home/ora12c/app/oracle/product/12.1.0/db_1/dbs/orapwcndba' ; } executing Memory Script Starting backup at 06-AUG-14 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=48 device type=DISK Finished backup at 06-AUG-14 contents of Memory Script: { sql clone "alter system set 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 by RMAN'' scope=spfile"; restore clone from service 'cndba_p' standby controlfile; } executing Memory Script sql statement: alter system set 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 by RMAN'' scope=spfile Starting restore at 06-AUG-14 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: restoring controlfile channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:07 output file name=/home/ora12c/app/oracle/oradata/CNDBA/controlfile/o1_mf_9y3rqtn9_.ctl output filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA/controlfile/o1_mf_9y3rqvky_.ctl Finished restore at 06-AUG-14 contents of Memory Script: { sql clone 'alter database mount standby database'; } executing Memory Script sql statement: alter database mount standbydatabase contents of Memory Script: { set newname for clone tempfile 1to new; set newname for clone tempfile 2to new; set newname for clone tempfile 3to new; switchclone tempfile all; set newname for clone datafile 1to new; set newname for clone datafile 3to new; set newname for clone datafile 4to new; set newname for clone datafile 5to new; set newname for clone datafile 6to new; set newname for clone datafile 7to new; set newname for clone datafile 8to new; set newname for clone datafile 9to new; set newname for clone datafile 10to new; restore from service 'cndba_p' 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/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_temp_%u_.tmp in controlfile renamed tempfile 2 to/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_temp_%u_.tmp in controlfile renamed tempfile 3 to/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_temp_%u_.tmp in controlfile 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 06-AUG-14 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00001 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:01:37 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00003 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:01:25 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifying datafile(s)to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00004 to/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:25 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00005 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:35 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00006 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:01 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00007 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:01:15 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00008 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:35 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00009 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:01:15 channel ORA_AUX_DISK_1: starting datafilebackup set restore channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: specifyingdatafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile00010 to /home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_%u_.dbf channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:03 Finished restore at 06-AUG-14 sql statement: alter system archive logcurrent current log archived contents of Memory Script: { restore clone force from service 'cndba_p' archivelog from scn 1922781; switch clone datafile all; } executing Memory Script Starting restore at 06-AUG-14 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting archivedlog restore to default destination channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: restoring archivedlog archived log thread=1 sequence=18 channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:01 channel ORA_AUX_DISK_1: starting archivedlog restore to default destination channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: restoring archivedlog archived log thread=1 sequence=19 channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:02 channel ORA_AUX_DISK_1: starting archivedlog restore to default destination channel ORA_AUX_DISK_1: using networkbackup set from service cndba_p channel ORA_AUX_DISK_1: restoring archivedlog archived log thread=1 sequence=20 channel ORA_AUX_DISK_1: restore complete,elapsed time: 00:00:01 Finished restore at 06-AUG-14 datafile 1 switched to datafile copy input datafile copy RECID=12STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_9y48opp7_.dbf datafile 3 switched to datafile copy input datafile copy RECID=13STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_9y48rr3z_.dbf datafile 4 switched to datafile copy input datafile copy RECID=14STAMP=854916586 file name=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_undotbs1_9y48vf5v_.dbf datafile 5 switched to datafile copy input datafile copy RECID=15STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_9y48w6bx_.dbf datafile 6 switched to datafile copy input datafile copy RECID=16STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_9y48x8jb_.dbf datafile 7 switched to datafile copy input datafile copy RECID=17STAMP=854916586 file name=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_9y48xb36_.dbf datafile 8 switched to datafile copy input datafile copy RECID=18STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_system_9y48zp0f_.dbf datafile 9 switched to datafile copy input datafile copy RECID=19STAMP=854916586 filename=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_sysaux_9y490r5z_.dbf datafile 10 switched to datafile copy input datafile copy RECID=20STAMP=854916586 file name=/home/ora12c/app/oracle/oradata/CNDBA_S/datafile/o1_mf_users_9y493301_.dbf contents of Memory Script: { set until scn 1923489; recover standby clone database delete archivelog ; } executing Memory Script executing command: SET until clause Starting recover at 06-AUG-14 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 18is already on disk as file/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_18_9y49378o_.arc archived log for thread 1 with sequence 19is already on disk as file/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_19_9y49387d_.arc archived log for thread 1 with sequence 20is already on disk as file/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_20_9y493976_.arc archived log filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_18_9y49378o_.arcthread=1 sequence=18 archived log filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_19_9y49387d_.arcthread=1 sequence=19 archived log filename=/home/ora12c/app/oracle/fast_recovery_area/CNDBA_S/archivelog/2014_08_06/o1_mf_1_20_9y493976_.arcthread=1 sequence=20 media recovery complete, elapsed time:00:00:01 Finished recover at 06-AUG-14 Finished Duplicate Db at 06-AUG-14 RMAN>
duplicate 完成之後,備庫是mount的。
SQL> select open_mode from v$database; OPEN_MODE ---------------------------------------- MOUNTED SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ---------------------------------------- ---------- 2 PDB$SEED MOUNTED 3 PCNDBA MOUNTED SQL> alter database open; Database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ---------------------------------------- ---------- 2 PDB$SEED READ ONLY NO 3 PCNDBA MOUNTED SQL> alter pluggable database pcndbaopen; Pluggable database altered. SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ---------------------------------------- ---------- 2 PDB$SEED READ ONLY NO 3 PCNDBA READ ONLY NO
備庫是只讀的。
--查看主庫: SQL> select log_mode,open_mode ,database_role from v$database; LOG_MODE OPEN_MODE DATABASE_ROLE ------------ ------------------------------------ ARCHIVELOG READ WRITE PRIMARY --備庫: SQL> select log_mode,open_mode ,database_role from v$database; LOG_MODE OPEN_MODE DATABASE_ROLE ------------ ------------------------------------ ARCHIVELOG READ ONLY PHYSICAL STANDBY --啟動real-time apply: SQL> alter database recover managedstandby database using current logfile disconnect from session; Database altered. SQL> select open_mode from v$database; OPEN_MODE -------------------- READ ONLY WITH APPLY
--在主庫創建一個table: SQL> alter session set container=pcndba; Session altered. SQL> create table cndba as select * fromdba_users; create table cndba as select * fromdba_users * ERROR at line 1: ORA-01109: database not open SQL> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ---------------------------------------- ---------- 3 PCNDBA MOUNTED SQL> alter database open; Database altered. SQL> create table cndba as select * fromdba_users; Table created. SQL> alter system switch logfile; alter system switch logfile * ERROR at line 1: ORA-65040: operation not allowed fromwithin a pluggable database
注意:這裡可以看到,對於12c的庫,日志的切換只能在CDB中進行,也就是我們前面講的,DG 是在CDB 級別進行的。
SQL> alter system switch logfile; System altered.
備庫查詢:
SQL> select count(1) from cndba; select count(1) from cndba * ERROR at line 1: ORA-00942: table or view does not exist
提示表不存在,實際上,我們是在PDB裡創建的,切換到對應的PDB下,就可以查詢到了:
SQL> alter session container=pcndba; alter session container=pcndba * ERROR at line 1: ORA-00922: missing or invalid option SQL> alter session set container=pcndba; Session altered. SQL> select count(1) from cndba; COUNT(1) ---------- 36