共计 31946 个字符,预计需要花费 80 分钟才能阅读完成。
这篇文章将为大家详细讲解有关如何理解 Oracle 12c CDB 的 ADG,文章内容质量较高,因此丸趣 TV 小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
实验环境
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 pdb2drwxr-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 就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。