1 说明
在11.2及以上版本支持级联备库,就是第二备库从第一个备库接受redo日志,而不是直接从主库接受redo日志。这样会减少主库的压力。实际上和正常搭建DG没什么区别,只是改一下参数即可,这里通过采用ADG方式来搭建。
最多支持30个级联备库,为啥呢?因为LOG_ARCHIVE_DEST_n,只有31个。
2 实验
更多详细信息,参考官方文档:http://docs.oracle.com/database/121/SBYDB/log_transport.htm#SBYDB5126
2.1 准备工作
和正常搭建DG一样,安装数据库软件,创建相应的目录,拷贝参数文件,密码文件等。我这里演示的是,添加第三个级联备库过程。
2.2 主库修改参数
SQL> Alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(cndba_p,cndba_s,cndba_ss)' scope=both;
2.3 第一备库修改参数
SQL> Alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(cndba_p,cndba_s,cndba_ss)' scope=both;
SQL> alter system set LOG_ARCHIVE_DEST_2= 'SERVICE=cndba_ss VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=cndba_ss' scope=spfile;
2.4 第二备库修改参数
*.DB_UNIQUE_NAME=cndba_ss
*.FAL_SERVER=cndba_s
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(cndba_p,cndba_s,cndba_ss)'
*.LOG_ARCHIVE_DEST_1='LOCATION= USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=cndba_ss'
2.5 主备库创建TNSNAME
CNDBA_SS =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.173)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cndba)
)
)
[oracle@12cdg-p ~]$ tnsping cndba_ss
TNS Ping Utility for Linux: Version 12.1.0.2.0 - Production on 16-AUG-2017 17:36:54
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/12.1.0.2/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.173)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = cndba)))
OK (0 msec)
2.6 将第二备库启动到nomount
SQL> startup nomount pfile='/u01/app/oracle/product/12.1.0.2/db_1/dbs/initcndba.ora';
ORACLE instance started.
Total System Global Area 2348810240 bytes
Fixed Size 2927048 bytes
Variable Size 1409287736 bytes
Database Buffers 922746880 bytes
Redo Buffers 13848576 bytes
2.7 开始DUPLICATE
注意:还是主库和第二备库的DUPLICATE
[oracle@12cdg-p ~]$ rman target [email protected]_p auxiliary [email protected]_ss
Recovery Manager: Release 12.1.0.2.0 - Production on Wed Aug 16 17:38:28 2017
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA (DBID=216462194)
connected to auxiliary database: CNDBA (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck;
Starting Duplicate Db at 16-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=23 device type=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/12.1.0.2/db_1/dbs/orapwcndba' auxiliary format
'/u01/app/oracle/product/12.1.0.2/db_1/dbs/orapwcndba' ;
}
executing Memory Script
Starting backup at 16-AUG-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
Finished backup at 16-AUG-17
contents of Memory Script:
{
restore clone from service 'cndba_p' standby controlfile;
}
executing Memory Script
Starting restore at 16-AUG-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 cndba_p
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:04
output file name=/u01/app/oracle/oradata/cndba/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/cndba/control02.ctl
Finished restore at 16-AUG-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/pdbseed_temp012017-08-14_12-17-51-PM.dbf";
set newname for tempfile 3 to
"/u01/app/oracle/oradata/cndba/sihong/temp012017-08-14_12-17-51-PM.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/users01.dbf";
set newname for datafile 7 to
"/u01/app/oracle/oradata/cndba/pdbseed/sysaux01.dbf";
set newname for datafile 8 to
"/u01/app/oracle/oradata/cndba/sihong/system01.dbf";
set newname for datafile 9 to
"/u01/app/oracle/oradata/cndba/sihong/sysaux01.dbf";
set newname for datafile 10 to
"/u01/app/oracle/oradata/cndba/sihong/sihong_users01.dbf";
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 /u01/app/oracle/oradata/cndba/temp01.dbf in control file
renamed tempfile 2 to /u01/app/oracle/oradata/cndba/pdbseed/pdbseed_temp012017-08-14_12-17-51-PM.dbf in control file
renamed tempfile 3 to /u01/app/oracle/oradata/cndba/sihong/temp012017-08-14_12-17-51-PM.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
Starting restore at 16-AUG-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 cndba_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:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cndba_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:26
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cndba_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:07
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/cndba/pdbseed/system01.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 cndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/cndba/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 cndba_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/pdbseed/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/cndba/sihong/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/cndba/sihong/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service cndba_p
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/cndba/sihong/sihong_users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 16-AUG-17
sql statement: alter system archive log current
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=3 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/system01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/undotbs01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/pdbseed/system01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=7 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/users01.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=8 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/pdbseed/sysaux01.dbf
datafile 8 switched to datafile copy
input datafile copy RECID=9 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/sihong/system01.dbf
datafile 9 switched to datafile copy
input datafile copy RECID=10 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/sihong/sysaux01.dbf
datafile 10 switched to datafile copy
input datafile copy RECID=11 STAMP=952191686 file name=/u01/app/oracle/oradata/cndba/sihong/sihong_users01.dbf
Finished Duplicate Db at 16-AUG-17
2.8 打开第二备库并启用MRP
SQL> alter database open;
Database altered.
SQL> alter database recover managed standby database disconnect;
Database altered.
–查看MRP进程
SQL> select process,status from v$managed_standby;
PROCESS STATUS
--------- ------------
ARCH CLOSING
ARCH CLOSING
ARCH CONNECTED
ARCH CLOSING
RFS IDLE
RFS IDLE
RFS IDLE
MRP0 WAIT_FOR_LOG
8 rows selected.
–数据库状态
SQL> select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
---------------- --------------------
PHYSICAL STANDBY READ ONLY WITH APPLY
2.9 查看日志序列号
主库:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
46
第一备库:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
46
第二备库:
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
46
2.9.1 主库切换日志
SQL> alter system switch logfile;
System altered.
–再查看日志序列号,全部都为47
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
47
至此级联备库搭建成功。