Oracle 12c 的DataGuard 是在CDB 级别进行的,所以我们的配置都是从CDB角度出发。
测试里主备库的数据库CDB名称相同。
1 环境说明
OS Version:
[root@dg1 yum.repos.d]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.3 (Maipo)
[root@dg1 yum.repos.d]# uname -r
3.10.0-514.el7.x86_64
DB Version:
SQL> select * from v$version;
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
PL/SQL Release 12.2.0.1.0 - Production 0
CORE 12.2.0.1.0 Production 0
TNS for Linux: Version 12.2.0.1.0 - Production 0
NLSRTL Version 12.2.0.1.0 - Production 0
SQL> col NAME_COL_PLUS_PDB_NAME for a30
SQL> show pdbs
NAME_COL_PLUS_PDB_CON_ID NAME_COL_PLUS_PDB_NAME NAME_COL_P NAM
------------------------ ------------------------------ ---------- ---
3 PDBCNDBA READ WRITE NO
2 PDB$SEED READ ONLY NO
Database DB_UNIQUE_NAME Oracle Net Service Name
Primary PDBCNDBA_P PDBCNDBA_P
Physical standby PDBCNDBA_S PDBCNDBA_S
[root@dg1 /]# cat /etc/hosts
127.0.0.1 localhost
192.168.1.60 dg1
192.168.1.61 dg2
主库 :PDBCNDBA_P 备库:PDBCNDBA_S
2 主库启动FORCE LOGGING
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDBCNDBA READ WRITE
SQL> conn /as sysdba
Connected.
SQL> alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FORCE_LOGGING
---------------------------------------
YES
3 启动归档模式
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/12.1.0/db_1/dbs/arch
Oldest online log sequence 1
Current log sequence 2
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1593835520 bytes
Fixed Size 8793256 bytes
Variable Size 1023411032 bytes
Database Buffers 553648128 bytes
Redo Buffers 7983104 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> show parameter recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string
db_recovery_file_dest_size big integer 0
recovery_parallelism integer 0
remote_recovery_file_dest string
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/product/12.1.0/db_1/dbs/arch
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
SQL> alter system set log_archive_dest_1='location=/u01/archive/' scope=spfile;
System altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archive/
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
SQL> alter database open;
Database altered.
SQL> col name for a30
SQL> col open_mode for a30
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ------------------------------
PDB$SEED READ ONLY
PDBCNDBA MOUNTED
SQL> alter pluggable database pdbcndba open;
Pluggable database altered.
SQL> select name,open_mode from v$pdbs;
NAME OPEN_MODE
------------------------------ ------------------------------
PDB$SEED READ ONLY
PDBCNDBA READ WRITE
4 在主库添加 standby redo logfile
在Oracle 12c的架构里,online redo log 和控制文件是保存在CDB中的,PDB中只有运行需要的数据文件,
所以我们这里加standby redo log,也是在CDB中加。
查看 Primary 库的 REDO 相关信息:
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL>
SQL> select group#, members, bytes from v$log;
GROUP# MEMBERS BYTES
---------- ---------- ----------
1 1 209715200
2 1 209715200
3 1 209715200
SQL> select member from v$logfile;
MEMBER
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/cndba/redo03.log
/u01/app/oracle/oradata/cndba/redo02.log
/u01/app/oracle/oradata/cndba/redo01.log
SQL> alter database add standby logfile '/u01/app/oracle/oradata/cndba/stdredo01.log' size 200M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/cndba/stdredo02.log' size 200M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/cndba/stdredo03.log' size 200M;
Database altered.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/cndba/stdredo04.log' size 200M;
Database altered.
SQL> select member from v$logfile;
MEMBER
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/cndba/redo03.log
/u01/app/oracle/oradata/cndba/redo02.log
/u01/app/oracle/oradata/cndba/redo01.log
/u01/app/oracle/oradata/cndba/stdredo01.log
/u01/app/oracle/oradata/cndba/stdredo02.log
/u01/app/oracle/oradata/cndba/stdredo03.log
/u01/app/oracle/oradata/cndba/stdredo04.log
7 rows selected.
5 分别在主备库配置监听并启动
--这里直接使用netmgr工具生成:注意静态监听注册中配置的pdb。
[oracle@dg1 admin]$ cat 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 = cndba)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0/db_1)
(SID_NAME = cndba)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
[oracle@dg1 admin]$ lsnrctl reload
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 25-MAY-2017 16:40:25
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dg1)(PORT=1521)))
The command completed successfully
6 分别在主备库配置tnsnames.ora
[oracle@dg2 admin]$ cat 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.
CNDBA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cndba)
)
)
PDBCNDBA_P =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.60)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = cndba)
)
)
PDBCNDBA_S =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = cndba)
)
)
配置完成后,使用tnsping 命令校验,切记要相互ping 通方可继续后面的操作,如果不通的话
检查防火墙有没有关或者1521 端口有没有关,tnsname.ora 配置是否正确,一般是这些原因,防火墙占多数原因。
[oracle@dg1 dbs]$ tnsping pdbcndba_p
TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 25-MAY-2017 19:50:19
Copyright (c) 1997, 2016, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/12.1.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.60)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = cndba)))
OK (10 msec)
[oracle@dg1 dbs]$ tnsping pdbcndba_s
TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 25-MAY-2017 19:50:20
Copyright (c) 1997, 2016, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/12.1.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = cndba)))
OK (0 msec)
7 在备库创建必要的目录
--主库目录
[oracle@dg1 oracle]$ ls
admin audit cfgtoollogs checkpoints diag oradata product tfa
[oracle@dg1 cndba]$ pwd
/u01/app/oracle/admin/cndba
[oracle@dg1 cndba]$ ls
adump dpdump pfile xdb_wallet
--备库目录
[oracle@dg2 oracle]$ ls
cfgtoollogs checkpoints diag product tfa
[oracle@dg2 oracle]$ mkdir -p /u01/app/oracle/admin/cndba/adump
[oracle@dg2 oracle]$ mkdir -p /u01/app/oracle/oradata
8 在主库创建pfile 文件并修改pfile 内容
SQL> create pfile from spfile;
File created.
在pfile中添加如下内容:
*.db_name='cndba'
*.db_unique_name='pdbcndba_p'
*.log_archive_config='dg_config=(pdbcndba_p,pdbcndba_s)'
*.log_archive_dest_1='location=/u01/archive valid_for=(all_logfiles,all_roles) db_unique_name=pdbcndba_p'
*.log_archive_dest_2='service=pdbcndba_s lgwr affirm sync valid_for=(online_logfiles,primary_role) db_unique_name=pdbcndba_s'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='pdbcndba_s'
*.log_file_name_convert='/u01/app/oracle/oradata/cndba','/u01/app/oracle/oradata/cndba'
*.db_file_name_convert='/u01/app/oracle/oradata/cndba','/u01/app/oracle/oradata/cndba'
以下参数即使对应的参数相同也配置上,以防止出错。
http://www.cndba.cn/leo1990/article/1934
*.log_file_name_convert='/u01/app/oracle/oradata/cndba','/u01/app/oracle/oradata/cndba'
*.db_file_name_convert='/u01/app/oracle/oradata/cndba','/u01/app/oracle/oradata/cndba'
用新参数重启数据库:
[oracle@dg1 dbs]$ sqlplus /nolog
SQL*Plus: Release 12.2.0.1.0 Production on Thu May 25 17:29:40 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
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 1593835520 bytes
Fixed Size 8793256 bytes
Variable Size 1023411032 bytes
Database Buffers 553648128 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.
SQL>
9 将主库的口令文件copy到备库
我这里主备库的CDB实例相同,如果不同,可以使用orapwd命令重建。
[oracle@dg1 dbs]$ pwd
/u01/app/oracle/product/12.1.0/db_1/dbs
[oracle@dg1 dbs]$ scp orapwcndba 192.168.1.61://u01/app/oracle/product/12.1.0/db_1/dbs
The authenticity of host '192.168.1.61 (192.168.1.61)' can't be established.
ECDSA key fingerprint is 1a:21:d0:3b:3e:0c:71:f4:ca:9a:b5:d6:84:c2:81:3d.
Are you sure you want to continue connecting (yes/no) yes
Warning: Permanently added '192.168.1.61' (ECDSA) to the list of known hosts.
[email protected]'s password:
orapwcndba
10 将主库的参数文件copy到备库并修改
[oracle@dg1 dbs]$ scp initcndba.ora 192.168.1.61://u01/app/oracle/product/12.1.0/db_1/dbs
[email protected]'s password:
initcndba.ora 100% 1518 1.5KB/s 00:00
修改添加如下内容,在重新生成spfile:
*.db_name='cndba'
*.db_unique_name='pdbcndba_s'
*.log_archive_config='dg_config=(pdbcndba_p,pdbcndba_s)'
*.log_archive_dest_1='location=/u01/archive valid_for=(all_logfiles,all_roles) db_unique_name=pdbcndba_s'
*.log_archive_dest_2='service=pdbcndba_p lgwr affirm sync valid_for=(online_logfiles,primary_role) db_unique_name=pdbcndba_p'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
*.fal_server='pdbcndba_p'
*.log_file_name_convert='/u01/app/oracle/oradata/cndba','/u01/app/oracle/oradata/cndba'
*.db_file_name_convert='/u01/app/oracle/oradata/cndba','/u01/app/oracle/oradata/cndba'
注意修改控制文件的路径,也使用新路径。
SQL> create spfile from pfile;
File created.
11 用spfile 将备库启动到nomount 状态
SQL> conn /as sysdba
Connected to an idle instance.
SQL> create spfile from pfile
2 /
File created.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1593835520 bytes
Fixed Size 8793256 bytes
Variable Size 1023411032 bytes
Database Buffers 553648128 bytes
Redo Buffers 7983104 bytes
11 用spfile 将备库启动到nomount 状态
SQL> conn /as sysdba
Connected to an idle instance.
SQL> create spfile from pfile
2 /
File created.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1593835520 bytes
Fixed Size 8793256 bytes
Variable Size 1023411032 bytes
Database Buffers 553648128 bytes
Redo Buffers 7983104 bytes
11 开始进行Active duplicate
[oracle@dg1 ~]$ rman target sys/oracle@pdbcndba_p auxiliary sys/oracle@pdbcndba_s;
Recovery Manager: Release 12.2.0.1.0 - Production on Thu May 25 17:51:56 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA (DBID=209386493)
connected to auxiliary database: CNDBA (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck dorecover;
Starting Duplicate Db at 25-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=36 device type=DISK
current log archived
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/12.1.0/db_1/dbs/orapwcndba' auxiliary format
'/u01/app/oracle/product/12.1.0/db_1/dbs/orapwcndba' ;
}
executing Memory Script
Starting backup at 25-MAY-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=68 device type=DISK
Finished backup at 25-MAY-17
contents of Memory Script:
{
restore clone from service 'pdbcndba_p' standby controlfile;
}
executing Memory Script
Starting restore at 25-MAY-17
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 pdbcndba_p
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/cndba/control01.ctl
output file name=/u01/app/oracle/oradata/cndba/control02.ctl
Finished restore at 25-MAY-17
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
"/u01/app/oracle/oradata/cndba/temp01.dbf";
set newname for tempfile 2 to
"/u01/app/oracle/oradata/cndba/pdbseed/temp012017-05-25_14-50-23-493-PM.dbf";
set newname for tempfile 3 to
"/u01/app/oracle/oradata/cndba/pdbcndba/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/cndba/system01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/cndba/sysaux01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/cndba/undotbs01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/cndba/pdbseed/system01.dbf";
set newname for datafile 6 to
"/u01/app/oracle/oradata/cndba/pdbseed/sysaux01.dbf";
set newname for datafile 7 to
"/u01/app/oracle/oradata/cndba/users01.dbf";
set newname for datafile 8 to
"/u01/app/oracle/oradata/cndba/pdbseed/undotbs01.dbf";
set newname for datafile 9 to
"/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf";
set newname for datafile 10 to
"/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf";
set newname for datafile 11 to
"/u01/app/oracle/oradata/cndba/pdbcndba/undotbs01.dbf";
set newname for datafile 12 to
"/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf";
restore
from nonsparse from service
'pdbcndba_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 /u01/app/oracle/oradata/cndba/temp01.dbf in control file
renamed tempfile 2 to /u01/app/oracle/oradata/cndba/pdbseed/temp012017-05-25_14-50-23-493-PM.dbf in control file
renamed tempfile 3 to /u01/app/oracle/oradata/cndba/pdbcndba/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
executing command: SET NEWNAME
Starting restore at 25-MAY-17
using channel ORA_AUX_DISK_1
skipping datafile 5; already restored to SCN 1439054
skipping datafile 6; already restored to SCN 1439054
skipping datafile 8; already restored to SCN 1439054
skipping datafile 9; already restored to SCN 1445997
skipping datafile 10; already restored to SCN 1445997
skipping datafile 11; already restored to SCN 1445997
skipping datafile 12; already restored to SCN 1445997
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service pdbcndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/cndba/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:26
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service pdbcndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/cndba/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service pdbcndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/cndba/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 pdbcndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/cndba/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 25-MAY-17
sql statement: alter system archive log current
current log archived
contents of Memory Script:
{
restore clone force from service 'pdbcndba_p'
archivelog from scn 1556302;
switch clone datafile all;
}
executing Memory Script
Starting restore at 25-MAY-17
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 pdbcndba_p
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=15
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
channel ORA_AUX_DISK_1: starting archived log restore to default destination
channel ORA_AUX_DISK_1: using network backup set from service pdbcndba_p
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=16
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 pdbcndba_p
channel ORA_AUX_DISK_1: restoring archived log
archived log thread=1 sequence=17
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 25-MAY-17
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=7 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbseed/system01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=8 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbseed/sysaux01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=9 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/users01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=10 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbseed/undotbs01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=11 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbcndba/system01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=12 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbcndba/sysaux01.dbf
datafile 11 switched to datafile copy
input datafile copy RECID=13 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbcndba/undotbs01.dbf
datafile 12 switched to datafile copy
input datafile copy RECID=14 STAMP=944936906 file name=/u01/app/oracle/oradata/cndba/pdbcndba/users01.dbf
contents of Memory Script:
{
set until scn 1556487;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 25-MAY-17
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 15 is already on disk as file /u01/archive/1_15_944923713.dbf
archived log for thread 1 with sequence 16 is already on disk as file /u01/archive/1_16_944923713.dbf
archived log for thread 1 with sequence 17 is already on disk as file /u01/archive/1_17_944923713.dbf
archived log file name=/u01/archive/1_15_944923713.dbf thread=1 sequence=15
archived log file name=/u01/archive/1_16_944923713.dbf thread=1 sequence=16
archived log file name=/u01/archive/1_17_944923713.dbf thread=1 sequence=17
media recovery complete, elapsed time: 00:00:00
Finished recover at 25-MAY-17
Finished Duplicate Db at 25-MAY-17
12 打开备库并并启动apply
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 PDBCNDBA MOUNTED
SQL> alter database open;
Database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBCNDBA MOUNTED
SQL> alter pluggable database pdbcndba open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBCNDBA 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 managed standby database using current logfile disconnect from session;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
13 验证DG
--在主库创建一个table:
SQL> alter session set container=pdbcndba;
Session altered.
SQL> show pdbs
SP2-0158: unknown SHOW option "pdbs "
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 PDBCNDBA MOUNTED
SQL> alter database open;
Database altered.
SQL> create table cndba as select * from dba_users;
Table created.
SQL> alter system switch logfile;
alter system switch logfile
*
ERROR at line 1:
ORA-65040: operation not allowed from within a pluggable database
注意:这里可以看到,对于12c的库,日志的切换只能在CDB中进行,也就是我们前面讲的,DG 是在CDB 级别进行的。
SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@dg1 dbs]$ sqlplus /nolog
SQL*Plus: Release 12.2.0.1.0 Production on Thu May 25 19:21:35 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected.
SQL> alter system switch logfile;
System altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBCNDBA READ WRITE NO
备库查询:
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 set container=pdbcndba;
Session altered.
SQL> select count(1) from cndba;
COUNT(1)
----------
37