您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何理解Oracle 12c CDB的ADG,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
實驗環境
OS:oracle linux 6.6
DB:oracle 12.1.0.1
主庫:chicago, pdb1, pdb2
備庫:boston, pdb1, pdb2
主庫操作
0. 確認tnsping可以在主庫與備庫之間相符訪問。如果能ping通,但是tnsping不通很有可能是防火墻沒有關閉
[root@snow ~]# service iptables stop
1. 主庫數據庫文件、控制文件、日志文件的規劃
[oracle@snow ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Fri May 1 17:47:28 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
SYS@chicago > show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
SYS@chicago >
select name from v$datafile
union
select name from v$controlfile
union
select member from v$logfile
union
select name from v$tempfile
union
select value from v$parameter where name='spfile';
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/chicago/control01.ctl
/home/oracle/dbfile/chicago/control02.ctl
/home/oracle/dbfile/chicago/pdb1/SAMPLE_SCHEMA_users01.dbf
/home/oracle/dbfile/chicago/pdb1/example01.dbf
/home/oracle/dbfile/chicago/pdb1/pdb1_temp01.dbf
/home/oracle/dbfile/chicago/pdb1/sysaux01.dbf
/home/oracle/dbfile/chicago/pdb1/system01.dbf
/home/oracle/dbfile/chicago/pdbseed/pdbseed_temp01.dbf
/home/oracle/dbfile/chicago/pdbseed/sysaux01.dbf
/home/oracle/dbfile/chicago/pdbseed/system01.dbf
/home/oracle/dbfile/chicago/redo01.log
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/chicago/redo02.log
/home/oracle/dbfile/chicago/redo03.log
/home/oracle/dbfile/chicago/sysaux01.dbf
/home/oracle/dbfile/chicago/system01.dbf
/home/oracle/dbfile/chicago/temp01.dbf
/home/oracle/dbfile/chicago/undotbs01.dbf
/home/oracle/dbfile/chicago/users01.dbf
/u01/app/oracle/product/12.1.0.1/db_1/dbs/spfilechicago.ora
19 rows selected.
2. 主庫現有3組redo,為此創建4組standby logfile group
SYS@chicago > select group#,bytes/1024/1024 from v$log;
GROUP# BYTES/1024/1024
---------- ---------------
1 50
2 50
3 50
SYS@chicago >
alter database add standby logfile group 4 ('/home/oracle/dbfile/chicago/redo04.log') size 50m;
alter database add standby logfile group 5 ('/home/oracle/dbfile/chicago/redo05.log') size 50m;
alter database add standby logfile group 6 ('/home/oracle/dbfile/chicago/redo06.log') size 50m;
alter database add standby logfile group 7 ('/home/oracle/dbfile/chicago/redo07.log') size 50m;
3. 主庫設置foece logging
SYS@chicago > alter database force logging;
SYS@chicago > shutdown immediate;
4. 主庫創建pfile
SYS@chicago > create pfile from spfile;
SYS@chicago > exit
5. 向主庫的pfile添加內容
[oracle@snow ~]$ cd $ORACLE_HOME/dbs
[oracle@snow dbs]$ vi initchicago.ora
*.audit_file_dest='/u01/app/oracle/admin/chicago/adump'
*.audit_trail='db'
*.compatible='12.1.0.0.0'
*.control_files='/home/oracle/dbfile/chicago/control01.ctl','/home/oracle/dbfile/chicago/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='chicago'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=chicagoXDB)'
*.log_archive_dest_1='LOCATION=/home/oracle/arch'
*.log_archive_format='%t_%s_%r.arc'
*.memory_target=1440m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
#for ADG
DB_UNIQUE_NAME=chicago
LOG_ARCHIVE_CONFIG='DG_CONFIG=(chicago,boston)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/home/oracle/arch
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=chicago'
LOG_ARCHIVE_DEST_2=
'SERVICE=boston ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=boston'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
FAL_SERVER=boston
FAL_CLIENT=chicago
DB_FILE_NAME_CONVERT='boston','chicago'
LOG_FILE_NAME_CONVERT='boston','chicago'
STANDBY_FILE_MANAGEMENT=AUTO
6. 復制主庫的pfile文件,修改為備庫的pfile
[oracle@snow dbs]$ cp initchicago.ora initboston.ora
[oracle@snow dbs]$ vi initboston.ora
*.audit_file_dest='/u01/app/oracle/admin/boston/adump'
*.audit_trail='db'
*.compatible='12.1.0.0.0'
*.control_files='/home/oracle/dbfile/boston/control01.ctl','/home/oracle/dbfile/boston/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='chicago'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=chicagoXDB)'
*.log_archive_dest_1='LOCATION=/home/oracle/arch'
*.log_archive_format='%t_%s_%r.arc'
*.memory_target=1440m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
#for ADG
DB_UNIQUE_NAME=boston
LOG_ARCHIVE_CONFIG='DG_CONFIG=(boston,chicago)'
LOG_ARCHIVE_DEST_1=
'LOCATION=/home/oracle/arch
VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
DB_UNIQUE_NAME=boston'
LOG_ARCHIVE_DEST_2=
'SERVICE=boston ASYNC
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
DB_UNIQUE_NAME=chicago'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
FAL_SERVER=chicago
FAL_CLIENT=boston
DB_FILE_NAME_CONVERT='chicago','boston'
LOG_FILE_NAME_CONVERT='chicago','boston'
STANDBY_FILE_MANAGEMENT=AUTO
7. 將備庫的pfile文件scp到備庫的/u01/app/oracle/product/12.1.0/db_1/dbs
[oracle@snow dbs]$ scp initboston.ora boston:/u01/app/oracle/product/12.1.0/db_1/dbs
oracle@boston's password:
initboston.ora 100% 1141 1.1KB/s 00:00
8. 復制主庫的密碼文件,修改為備庫的密碼文件并scp到備庫的/u01/app/oracle/product/12.1.0/db_1/dbs
[oracle@snow dbs]$ cp orapwchicago orapwboston
[oracle@snow dbs]$ scp orapwboston boston:/u01/app/oracle/product/12.1.0/db_1/dbs
oracle@boston's password:
orapwboston 100% 7680 7.5KB/s 00:00
9. 修改主庫的$ORACLE_HOME/network/admin/tnsnames.ora,手工添加(藍色)備庫的boston部分。其中CHICAGO為CDB的鏈接字符串,PDB1為PDB的鏈接字符串。
[oracle@snow dbs]$ cd $ORACLE_HOME/network/admin
[oracle@snow admin]$ vi tnsnames.ora
BOSTON =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.13)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = boston)
)
)
CHICAGO =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = snow.oracle.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = chicago)
)
)
PDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.12)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb1)
)
)
備庫操作
10. 創建備庫所需目錄
和主庫一樣確認防火墻已經關閉
[root@boston ~]# service iptables stop
[oracle@boston ~]$ export ORACLE_SID=boston
[oracle@boston ~]$ mkdir -p $ORACLE_BASE/admin/boston/adump
[oracle@boston ~]$ mkdir -p dbfile/boston/pdbseed
[oracle@boston ~]$ mkdir -p dbfile/boston/pdb1
注意:如果只創建了dbfile/boston目錄,沒有創建pdbseed和pdb1目錄的話再后面的duplicate操作會失敗。
ORA-19504: failed to create file "/home/oracle/dbfile/boston/pdbseed/system01.dbf"
11. 為備庫創建靜態監聽,此步驟可以使用netmgr
[oracle@boston ~]$ vi $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/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 = boston)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/db_1)
(SID_NAME = boston)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = boston)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
12. 修改備庫tnsnames.ora,添加主庫的CHICAGO(藍色)
[oracle@boston ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
BOSTON =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.13)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = boston)
)
)
CHICAGO =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.12)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = chicago)
)
)
13. 備庫reload監聽器
[oracle@boston ~]$ lsnrctl
LSNRCTL> reload
主庫操作
14. 主庫從修改后的pfile創建spfile,啟動實例。此時關于ADG的配置信息將隨之實例的啟動生效。
[oracle@snow ~]$ sqlplus sys/oracle@chicago as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Fri May 1 18:13:45 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@chicago > create spfile from pfile;
File created.
SYS@chicago > startup
備庫操作
15. 備庫從修改后的pfile創建spfile,啟動實例到nomount狀態。
[oracle@boston dbs]$ sqlplus sys/oracle@boston as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Wed May 6 13:03:06 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SYS@boston > create spfile from pfile;
File created.
SYS@boston > startup nomount;
ORACLE instance started.
Total System Global Area 459304960 bytes
Fixed Size 2289544 bytes
Variable Size 381681784 bytes
Database Buffers 71303168 bytes
Redo Buffers 4030464 bytes
SYS@boston > exit
16. 使用rman duplicate來在線復制主庫。rman部分輸出比較多,命名語句使用高亮表標示,其它字體為屏幕輸出。
[oracle@boston ~]$ rman target sys/oracle@chicago auxiliary sys/oracle@boston
Recovery Manager: Release 12.1.0.1.0 - Production on Mon May 25 14:27:16 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
connected to target database: CHICAGO (DBID=1488305431)
connected to auxiliary database: CHICAGO (not mounted)
RMAN> duplicate target database for standby from active database dorecover nofilenamecheck;
Starting Duplicate Db at 25-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
current log archived
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/12.1.0.1/db_1/dbs/orapwchicago' auxiliary format
'/u01/app/oracle/product/12.1.0/db_1/dbs/orapwboston' ;
}
executing Memory Script
Starting backup at 25-MAY-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=265 device type=DISK
Finished backup at 25-MAY-15
contents of Memory Script:
{
restore clone from service 'chicago' standby controlfile;
}
executing Memory Script
Starting restore at 25-MAY-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 chicago
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/home/oracle/dbfile/boston/control01.ctl
output file name=/home/oracle/dbfile/boston/control02.ctl
Finished restore at 25-MAY-15
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/home/oracle/dbfile/boston/temp01.dbf";
set newname for tempfile 2 to
"/home/oracle/dbfile/boston/pdbseed/pdbseed_temp01.dbf";
set newname for tempfile 3 to
"/home/oracle/dbfile/boston/pdb1/pdb1_temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/home/oracle/dbfile/boston/system01.dbf";
set newname for datafile 3 to
"/home/oracle/dbfile/boston/sysaux01.dbf";
set newname for datafile 4 to
"/home/oracle/dbfile/boston/undotbs01.dbf";
set newname for datafile 5 to
"/home/oracle/dbfile/boston/pdbseed/system01.dbf";
set newname for datafile 6 to
"/home/oracle/dbfile/boston/users01.dbf";
set newname for datafile 7 to
"/home/oracle/dbfile/boston/pdbseed/sysaux01.dbf";
set newname for datafile 8 to
"/home/oracle/dbfile/boston/pdb1/system01.dbf";
set newname for datafile 9 to
"/home/oracle/dbfile/boston/pdb1/sysaux01.dbf";
set newname for datafile 10 to
"/home/oracle/dbfile/boston/pdb1/SAMPLE_SCHEMA_users01.dbf";
set newname for datafile 11 to
"/home/oracle/dbfile/boston/pdb1/example01.dbf";
restore
from service 'chicago' 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/oracle/dbfile/boston/temp01.dbf in control file
renamed tempfile 2 to /home/oracle/dbfile/boston/pdbseed/pdbseed_temp01.dbf in control file
renamed tempfile 3 to /home/oracle/dbfile/boston/pdb1/pdb1_temp01.dbf 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 25-MAY-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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /home/oracle/dbfile/boston/system01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /home/oracle/dbfile/boston/sysaux01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /home/oracle/dbfile/boston/undotbs01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /home/oracle/dbfile/boston/pdbseed/system01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /home/oracle/dbfile/boston/users01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /home/oracle/dbfile/boston/pdbseed/sysaux01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /home/oracle/dbfile/boston/pdb1/system01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /home/oracle/dbfile/boston/pdb1/sysaux01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /home/oracle/dbfile/boston/pdb1/SAMPLE_SCHEMA_users01.dbf
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 chicago
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00011 to /home/oracle/dbfile/boston/pdb1/example01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 25-MAY-15
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'chicago'
archivelog from scn 2165528;
switch clone datafile all;
}
executing Memory Script
Starting restore at 25-MAY-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 chicago
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=82
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 chicago
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=83
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 chicago
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=84
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 25-MAY-15
datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=880640897 file name=/home/oracle/dbfile/boston/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=8 STAMP=880640897 file name=/home/oracle/dbfile/boston/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=9 STAMP=880640897 file name=/home/oracle/dbfile/boston/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=10 STAMP=880640897 file name=/home/oracle/dbfile/boston/pdbseed/system01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=11 STAMP=880640897 file name=/home/oracle/dbfile/boston/users01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=12 STAMP=880640897 file name=/home/oracle/dbfile/boston/pdbseed/sysaux01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=13 STAMP=880640897 file name=/home/oracle/dbfile/boston/pdb1/system01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=14 STAMP=880640897 file name=/home/oracle/dbfile/boston/pdb1/sysaux01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=15 STAMP=880640897 file name=/home/oracle/dbfile/boston/pdb1/SAMPLE_SCHEMA_users01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=16 STAMP=880640897 file name=/home/oracle/dbfile/boston/pdb1/example01.dbf
contents of Memory Script:
{
set until scn 2165825;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 25-MAY-15
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 82 is already on disk as file /home/oracle/arch/1_82_878586712.arc
archived log for thread 1 with sequence 83 is already on disk as file /home/oracle/arch/1_83_878586712.arc
archived log for thread 1 with sequence 84 is already on disk as file /home/oracle/arch/1_84_878586712.arc
archived log file name=/home/oracle/arch/1_82_878586712.arc thread=1 sequence=82
archived log file name=/home/oracle/arch/1_83_878586712.arc thread=1 sequence=83
archived log file name=/home/oracle/arch/1_84_878586712.arc thread=1 sequence=84
media recovery complete, elapsed time: 00:00:00
Finished recover at 25-MAY-15
Finished Duplicate Db at 25-MAY-15
到此為止12c CDB ADG創建完畢。
備庫創建成功后,CDB處于mount狀態,角色處于物理備庫。 逐步開啟ADG。
[oracle@boston ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Mon May 25 14:30:12 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
SYS@boston > select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
MOUNTED PHYSICAL STANDBY
備庫執行ALTER DATABAE OPEN會將CDB置于open read only狀態。
SYS@boston > ALTER DATABASE OPEN;
Database altered.
備庫執行ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING ARCHIVED LOGFILE DISCONNECT將實時應用主庫傳遞過來的歸檔日志。和前面開啟的open read only疊加在一起成為active dataguard
SYS@boston > ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING ARCHIVED LOGFILE DISCONNECT;
Database altered.
SYS@boston > select open_mode,database_role from v$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ ONLY WITH APPLY PHYSICAL STANDBY
開啟ADG的過程,只會將CDB置于open read only,并不會將mount狀態的pdb1也開啟為open read only。
SYS@boston > show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED
SYS@boston > alter pluggable database all open;
Pluggable database altered.
測試ADG效果,在主庫的pdb1創建表空間后在備庫驗證是否可以同步。
主庫在pdb創建一個表空間tbs1
SYS@chicago > show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 MOUNTED
SYS@chicago >
SYS@chicago > alter pluggable database all open;
Pluggable database altered.
SYS@chicago > alter session set container=pdb1;
Session altered.
SYS@chicago > select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/chicago/undotbs01.dbf
/home/oracle/dbfile/chicago/pdb1/system01.dbf
/home/oracle/dbfile/chicago/pdb1/sysaux01.dbf
/home/oracle/dbfile/chicago/pdb1/SAMPLE_SCHEMA_users01.dbf
/home/oracle/dbfile/chicago/pdb1/example01.dbf
SYS@chicago > create tablespace tbs1 datafile '/home/oracle/dbfile/chicago/pdb1/tbs1.dbf' size 5m;
Tablespace created.
SYS@chicago > col file_name for a58
SYS@chicago > set lines 150
SYS@chicago > select file_name,file_id,con_id from cdb_data_files;
FILE_NAME FILE_ID CON_ID
---------------------------------------------------------- ---------- ----------
/home/oracle/dbfile/chicago/pdb1/system01.dbf 8 3
/home/oracle/dbfile/chicago/pdb1/sysaux01.dbf 9 3
/home/oracle/dbfile/chicago/pdb1/SAMPLE_SCHEMA_users01.dbf 10 3
/home/oracle/dbfile/chicago/pdb1/example01.dbf 11 3
/home/oracle/dbfile/chicago/pdb1/tbs1.dbf 12 3
在備庫驗證表空間tbs1同步成功。但是延時比較大,等了好久才同步成功。
SYS@boston > select file_name,file_id,con_id from cdb_data_files;
FILE_NAME FILE_ID CON_ID
---------------------------------------------------------- ---------- ----------
/home/oracle/dbfile/boston/pdb1/example01.dbf 11 3
/home/oracle/dbfile/boston/pdb1/SAMPLE_SCHEMA_users01.dbf 10 3
/home/oracle/dbfile/boston/pdb1/sysaux01.dbf 9 3
/home/oracle/dbfile/boston/pdb1/tbs1.dbf 12 3
/home/oracle/dbfile/boston/pdb1/system01.dbf 8 3
最后測試主庫添加pdb2,備庫的同步效果。使用圖形工具dbca在CDB chicago上創建新的pdb。
主庫創建pdb2的過程中后臺alert輸出如下:
CREATE PLUGGABLE DATABASE pdb2 ADMIN USER snow IDENTIFIED BY * ROLES=(CONNECT) file_name_convert=('/home/oracle/dbfile/chicago/pdbseed/system01.dbf','/home/oracle/dbfile/chicago/pdb2/system01.dbf',
'/home/oracle/dbfile/chicago/pdbseed/sysaux01.dbf','/home/oracle/dbfile/chicago/pdb2/sysaux01.dbf','/home/oracle/dbfile/chicago/pdbseed/pdbseed_temp01.dbf','/home/oracle/dbfile/chicago/pdb2/temp01.dbf')
Sat May 02 01:27:44 2015
****************************************************************
Pluggable Database PDB2 with pdb id - 4 is created as UNUSABLE.
If any errors are encountered before the pdb is marked as NEW,
then the pdb must be dropped
****************************************************************
Deleting old file#5 from file$
Deleting old file#7 from file$
Adding new file#13 to file$(old file#5)
Adding new file#14 to file$(old file#7)
Successfully created internal service pdb2 at open
ALTER SYSTEM: Flushing buffer cache inst=0 container=4 local
****************************************************************
Post plug operations are now complete.
Pluggable database PDB2 with pdb id - 4 is now marked as NEW.
****************************************************************
Completed: CREATE PLUGGABLE DATABASE pdb2 ADMIN USER snow IDENTIFIED BY * ROLES=(CONNECT) file_name_convert=('/home/oracle/dbfile/chicago/pdbseed/system01.dbf','/home/oracle/dbfile/chicago/pdb2/system01.dbf',
'/home/oracle/dbfile/chicago/pdbseed/sysaux01.dbf','/home/oracle/dbfile/chicago/pdb2/sysaux01.dbf','/home/oracle/dbfile/chicago/pdbseed/pdbseed_temp01.dbf','/home/oracle/dbfile/chicago/pdb2/temp01.dbf')
alter pluggable database pdb2 open
Pluggable database PDB2 dictionary check beginning
Pluggable Database PDB2 Dictionary check complete
Due to limited space in shared pool (need 6094848 bytes, have 3981120 bytes), limiting Resource Manager entities from 2048 to 32
Opening pdb PDB2 (4) with no Resource Manager plan active
Sat May 02 01:27:47 2015
Setting Resource Manager plan SCHEDULER[0x420E]:DEFAULT_MAINTENANCE_PLAN via scheduler window
Setting Resource Manager plan DEFAULT_MAINTENANCE_PLAN at pdb PDB2 (4) via parameter
Sat May 02 01:27:47 2015
XDB installed.
XDB initialized.
Pluggable database PDB2 opened read write
Completed: alter pluggable database pdb2 open
CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/home/oracle/dbfile/chicago/pdb2/pdb2_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/home/oracle/dbfile/chicago/pdb2/pdb2_users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
ALTER DATABASE DEFAULT TABLESPACE "USERS"
Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
Sat May 02 01:28:00 2015
TABLE SYS.WRI$_OPTSTAT_HISTHEAD_HISTORY: ADDED INTERVAL PARTITION SYS_P221 (42125) VALUES LESS THAN (TO_DATE(' 2015-05-03 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLE SYS.WRI$_OPTSTAT_HISTGRM_HISTORY: ADDED INTERVAL PARTITION SYS_P241 (42125) VALUES LESS THAN (TO_DATE(' 2015-05-03 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
Sat May 02 01:28:49 2015
Thread 1 cannot allocate new log, sequence 90
Private strand flush not complete
Current log# 2 seq# 89 mem# 0: /home/oracle/dbfile/chicago/redo02.log
Sat May 02 01:28:52 2015
Thread 1 advanced to log sequence 90 (LGWR switch)
Current log# 3 seq# 90 mem# 0: /home/oracle/dbfile/chicago/redo03.log
Sat May 02 01:28:53 2015
Archived Log entry 87 added for thread 1 sequence 89 ID 0x58b61e17 dest 1:
Sat May 02 01:28:53 2015
TT00: Standby redo logfile selected for thread 1 sequence 90 for destination LOG_ARCHIVE_DEST_2
與此同時在備庫端觀察alert日志查看同步效果。通過日志輸出,可以觀察到新的數據文件創建到新的目錄pdb2下。
boston alert.log
Recovery successfully copied file /home/oracle/dbfile/boston/pdb2/system01.dbf from /home/oracle/dbfile/boston/pdbseed/system01.dbf
Recovery created file /home/oracle/dbfile/boston/pdb2/system01.dbf
Successfully added datafile 13 to media recovery
Datafile #13: '/home/oracle/dbfile/boston/pdb2/system01.dbf'
Recovery copied files for tablespace SYSAUX
Recovery successfully copied file /home/oracle/dbfile/boston/pdb2/sysaux01.dbf from /home/oracle/dbfile/boston/pdbseed/sysaux01.dbf
Recovery created file /home/oracle/dbfile/boston/pdb2/sysaux01.dbf
Successfully added datafile 14 to media recovery
Datafile #14: '/home/oracle/dbfile/boston/pdb2/sysaux01.dbf'
Recovery created file /home/oracle/dbfile/boston/pdb2/pdb2_users01.dbf
Successfully added datafile 15 to media recovery
Datafile #15: '/home/oracle/dbfile/boston/pdb2/pdb2_users01.dbf'
Media Recovery Waiting for thread 1 sequence 90 (in transit)
RFS[2]: Selected log 5 for thread 1 sequence 91 dbid 1488305431 branch 878586712
Mon May 25 15:12:53 2015
主庫創建后的實例列表和文件分布
SYS@chicago > show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
4 PDB2 READ WRITE NO
SYS@chicago > select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/chicago/system01.dbf
/home/oracle/dbfile/chicago/sysaux01.dbf
/home/oracle/dbfile/chicago/undotbs01.dbf
/home/oracle/dbfile/chicago/pdbseed/system01.dbf
/home/oracle/dbfile/chicago/users01.dbf
/home/oracle/dbfile/chicago/pdbseed/sysaux01.dbf
/home/oracle/dbfile/chicago/pdb1/system01.dbf
/home/oracle/dbfile/chicago/pdb1/sysaux01.dbf
/home/oracle/dbfile/chicago/pdb1/SAMPLE_SCHEMA_users01.dbf
/home/oracle/dbfile/chicago/pdb1/example01.dbf
/home/oracle/dbfile/chicago/pdb1/tbs1.dbf
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/chicago/pdb2/system01.dbf
/home/oracle/dbfile/chicago/pdb2/sysaux01.dbf
/home/oracle/dbfile/chicago/pdb2/pdb2_users01.dbf
14 rows selected.
備庫的實例列表和文件分布
SYS@boston > show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ ONLY NO
4 PDB2 MOUNTED
SYS@boston > select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/boston/system01.dbf
/home/oracle/dbfile/boston/sysaux01.dbf
/home/oracle/dbfile/boston/undotbs01.dbf
/home/oracle/dbfile/boston/pdbseed/system01.dbf
/home/oracle/dbfile/boston/users01.dbf
/home/oracle/dbfile/boston/pdbseed/sysaux01.dbf
/home/oracle/dbfile/boston/pdb1/system01.dbf
/home/oracle/dbfile/boston/pdb1/sysaux01.dbf
/home/oracle/dbfile/boston/pdb1/SAMPLE_SCHEMA_users01.dbf
/home/oracle/dbfile/boston/pdb1/example01.dbf
/home/oracle/dbfile/boston/pdb1/tbs1.dbf
NAME
--------------------------------------------------------------------------------
/home/oracle/dbfile/boston/pdb2/system01.dbf
/home/oracle/dbfile/boston/pdb2/sysaux01.dbf
/home/oracle/dbfile/boston/pdb2/pdb2_users01.dbf
14 rows selected.
一些補充
主庫新建pdb2后不會自動添加tnsnames,為了客戶端連接需要手工添加藍色pdb2部分。
[oracle@snow admin]$ more tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.1.0.1/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
BOSTON =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = boston)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = boston)
)
)
CHICAGO =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.12)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = chicago)
)
)
LISTENER_ALEX =
(ADDRESS = (PROTOCOL = TCP)(HOST = snow.oracle.com)(PORT = 1521))
PDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.12)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb1)
)
)
PDB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.228.12)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pdb2)
)
)
主庫創建pdb2,備庫應用日志后也創建了pdb2,并且在制定目錄/home/oracle/dbfile/boston下創建了pdb2目錄來存放數據文件。
這本來是不需要擔心的地方,但是在HP Unix會出現問題。備庫應用日志后無法創建pdb的目錄導致創建失敗。每當主庫創建一個新的pdb之前需要在備庫手工創建相應的目錄才可以。
[oracle@boston boston]$ ll
total 2351032
-rw-r----- 1 oracle oinstall 18268160 May 25 15:26 control01.ctl
-rw-r----- 1 oracle oinstall 18268160 May 25 15:26 control02.ctl
drwxr-xr-x 2 oracle oinstall 4096 May 25 14:43 pdb1
drwxr-x--- 2 oracle oinstall 4096 May 25 15:12 pdb2
drwxr-xr-x 2 oracle oinstall 4096 May 25 14:31 pdbseed
-rw-r----- 1 oracle oinstall 52429312 May 25 14:28 redo01.log
-rw-r----- 1 oracle oinstall 52429312 May 25 14:28 redo02.log
-rw-r----- 1 oracle oinstall 52429312 May 25 14:28 redo03.log
-rw-r----- 1 oracle oinstall 52429312 May 25 15:12 redo04.log
-rw-r----- 1 oracle oinstall 52429312 May 25 15:26 redo05.log
-rw-r----- 1 oracle oinstall 52429312 May 25 14:28 redo06.log
-rw-r----- 1 oracle oinstall 52429312 May 25 14:28 redo07.log
-rw-r----- 1 oracle oinstall 807411712 May 25 15:13 sysaux01.dbf
-rw-r----- 1 oracle oinstall 828383232 May 25 15:13 system01.dbf
-rw-r----- 1 oracle oinstall 92282880 May 25 14:31 temp01.dbf
-rw-r----- 1 oracle oinstall 361766912 May 25 15:13 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 25 15:13 users01.dbf
關于如何理解Oracle 12c CDB的ADG就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。