Oracle 12c Data Guard 搭建手册

 

 

 

Oracle 12c 的DataGuard 是在CDB 级别进行的,所以我们的配置都是从CDB角度出发。

 

测试里主备库的数据库CDB名称相同。

 

1  环境说明

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 做我们的主库。

 

 

2  主库启动FORCE LOGGING

 

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

 

3  启动归档模式

 

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

 

 

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> 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.

 

 

5  分别在主备库配置监听并启动

 

--这里直接使用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

 

 

6  分别在主备库配置tnsnames.ora

 

 

[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

 

 

7  在备库创建必要的目录

 

可以参考主库的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

 

 

8  在主库创建pfile 文件并修改pfile 内容

 

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>

 

9  将主库的口令文件copy到备库

 

我这里主备库的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]$

 

10 将主库的参数文件copy到备库并修改

 

[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.

 

 

 

11 用spfile 将备库启动到nomount 状态

 

 

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>

 

 

12 开始进行Active duplicate

 

 

[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>

 

13 打开备库并并启动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 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

 

 

 

14 验证DG

 

--在主库创建一个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

 

 

 

 

 

 

--------------------------------------------------------------------------------------------

版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!

 

AboutDave:

--------------------------------------------------------------------------------------------

QQ:      251097186

Email:    [email protected]

Blog:     http://blog.csdn.net/tianlesoftware

Weibo:    http://weibo.com/tianlesoftware

Twitter:  http://twitter.com/tianlesoftware

Facebook: http://www.facebook.com/tianlesoftware

Linkedin: http://cn.linkedin.com/in/tianlesoftware

 

Dave 的QQ群:

--------------------------------------------------------------------------------------------

注意:加群必须注明表空间和数据文件关系 | 不要重复加群

CNDBA_1: 104207940 (满)    CNDBA_2: 62697716 (满)   CNDBA_3: 283816689

CNDBA_4: 391125754   CNDBA_5: 62697850    CNDBA_6: 62697977   CNDBA_7: 142216823(满)

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。