在已有一套两节点rac数据库,拟部署dataguard使用2节点rac作为备库,一共4台机器。也适用rac数据库迁移到rac环境。
Primary | Standby | |
---|---|---|
DB Version | 11.2.0.4 | 11.2.0.4 |
Hostname | rac1/rac2 | rac1-std/rac2-std |
DB_NAME | orcldb | orcldbstd |
DB_UNIQUE_NAME | orcldb | orcldbstd |
Instance_Name | orcldb1/orcldb2 | orcldbstd1/orcldbstd2 |
DB Listener | 1521 | 1521 |
DB Storage | ASM | ASM |
ASM for DB files | +DATA/orcldb/datafile/ | +DATA/orcldbstd/datafile/ |
ASM for TEMP files | +DATA/orcldb/tempfile/ | +DATA/orcldbstd/tempfile/ |
ASM for LOG files | +DATA/orcldb/onlinelog/ | +DATA/orcldbstd/onlinelog/ |
ORACLE_HOME | /u01/app/oracle/product/11.2.0/db_1/ | /u01/app/oracle/product/11.2.0/db_1/ |
OS | CentOS 7.4 | CentOS 7.4 |
部署之前可以修改备库的hostname以及hosts文件方便区分服务器
cat /etc/hosts
#PRIMARY
#public ip ent0
172.16.4.121 rac1
172.16.4.122 rac2
#priv ip ent1
10.10.10.121 rac1-prv
10.10.10.122 rac2-prv
#vip ip
172.16.4.123 rac1-vip
172.16.4.124 rac2-vip
#scan ip
172.16.4.125 rac-scan
#STANDBY
#public ip ent0
172.16.4.131 rac1-std
172.16.4.132 rac2-std
#priv ip ent1
10.10.10.121 rac1-prv-std
10.10.10.122 rac2-prv-std
#vip ip
172.16.4.133 rac1-vip-std
172.16.4.134 rac2-vip-std
#scan ip
172.16.4.135 rac-scan-std
1、修改主库强制归档以及开启归档模式
[oracle@rac1:/home/oracle]$sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jul 3 15:37:09 2018
Copyright © 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount;
SQL> alter system set log_archive_dest_1='location=+arch' scope=spfile;
System altered.
SQL> alter database archivelog;
Database altered.
SQL> alter database force logging;
Database altered.
开启数据库
SQL> alter database open;
2、修改主库初始化参数
当主库已开启force logging之后再进行如下操作
alter database force logging;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcldb,orcldbstd)' scope=both sid='*';
alter system set log_archive_dest_1='LOCATION=+arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcldb' scope=spfile;
alter system set LOG_ARCHIVE_DEST_2='SERVICE=orcldbstd LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcldbstd' scope=both sid='*';
alter system set fal_client='orcldb' scope=both sid='*';
alter system set FAL_SERVER='orcldbstd' scope=both sid='*';
alter system set standby_file_management=AUTO scope=both sid='*';
alter system set DB_FILE_NAME_CONVERT='+data','+data' scope=spfile sid='*';
alter system set LOG_FILE_NAME_CONVERT='+data','+data' scope=spfile sid='*';
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
alter system set remote_login_passwordfile='EXCLUSIVE' scope=spfile;
alter system set PARALLEL_EXECUTION_MESSAGE_SIZE=8192 scope=spfile;
重启数据库
备注:
log_archive_dest_1这里写主库arch路径
DB_FILE_NAME_CONVERT,LOG_FILE_NAME_CONVERT参数需要已'备库路径','主库路径'一组为准则
参数解析:
LOG_ARCHIVE_CONFIG:列出主备库上的DB_UNIQUE_NAME 参数。默认情况下,定义该参数能确保主备库数据库能够互相识别对方
LOG_ARCHIVE_DEST_1:本地归档路径。Primary与Standby需要定义各自的归档路径
LOG_ARCHIVE_DEST_2:设置redo log的传输方式(sync or async)以及传输目标(即standby apply node),当前节点设置的均为另一端数据库的db_unique_name,并且其中的service的值需要与tnsnames.ora别名相同。
FAL_CLIENT:(Fetch Archive Log)用来解决归档裂缝,定义的客户端(获取日志的客户端),参数取自Oracle Net Service Name
FAL_SERVER:当主库转为备库的时候此参数会生效。通过网络向FAL_CLIENT发送缺失的日志,参数取自Oracle Net Service Name上述例子当rac转为备库时,会向std获取redo或者归档应用。
STANDBY_FILE_MANAGEMENT:当主库转为备库的时候此参数会生效。用来控制是否自动将Primary数据库增加表空间或数据文件的改动,传播到物理Standby数据库。AUTO:如果该参数值设置为AUTO,则Primary数据库执行的表空间创建操作也会被传播到物理Standby数据库上执行。
MANUAL:如果设置为MANUAL或未设置任何值(默认值是MANUAL),需要手工复制新创建的数据文件到物理Standby服务器。
DB_FILE_NAME_CONVERT:当主库转为备库的时候此参数会生效。主数据库和备用数据库的数据文件转换目录对映(如果两数据库的目录结构不一样),如果有多个对映,逐一指明对映关系。注意: primary上的该参数仅在主备switch over后生效,格式应保持一致
LOG_FILE_NAME_CONVERT:当主库转为备库的时候此参数会生效。定义主备log文件的存放路径转换
3、主库增加Standby redo log
如果2节点RAC主库每个thread redo log有N组,standby redo log则需要(N+1)*2组。
主库查询redo 日志组数,有2个thread,每个thread有2组日志,standby则需要6组
SQL> select group#,thread#,members,status from v$log;
GROUP# THREAD# MEMBERS STATUS
---------- ---------- ---------- ----------------
1 1 1 INACTIVE
2 1 1 CURRENT
3 2 1 INACTIVE
4 2 1 CURRENT
主库增加standby日志组:
alter database add standby logfile group 11 '+data' size 50m;
alter database add standby logfile group 12 '+data' size 50m;
alter database add standby logfile group 13 '+data' size 50m;
alter database add standby logfile group 14 '+data' size 50m;
alter database add standby logfile group 15 '+data' size 50m;
alter database add standby logfile group 16 '+data' size 50m;
确认主库加的standby日志是否已创建
SQL> select group#,thread# from v$standby_log;
GROUP# THREAD#
---------- ----------
11 0
12 0
13 0
14 0
15 0
16 0
6 rows selected.
4、在rac两个实例以及备库添加tnsnames字符串
[oracle@rac1:/u01/app/oracle/product/11.2.0/db_1/network/admin]$vi tnsnames.ora
主库用scan ip
orcldb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldb)
)
)
orcldb1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldb)
)
)
orcldb2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldb)
)
)
orcldbstd =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan-std)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldbstd)
)
)
orcldbstd1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip-std)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldbstd)
)
)
orcldbstd2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip-std)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcldbstd)
)
)
备注:备库日志应用基于tnsnames
5、 在主库上生成用于备库的参数文件
SQL> create pfile='initorcldbstd1.ora' from spfile;
6、 将主库的参数文件,密码文件拷贝到备库
对参数文件,密码文件重命名符合实例命名规范(必须拷贝密码文件)
节点1
scp root@rac1:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldb1 /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldbstd1
节点2
scp root@rac1:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldb1 /u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldbstd2
7、 在备库上更改参数文件,修改参数以及创建目录结构
创建备库的归档目录以及各个数据文件目录
mkdir -p /u01/app/oracle/admin/orcldb/adump
[oracle@orcldb:/u01/app/oracle/product/11.2.0/db_1/dbs]$vi initorcldbstd1.ora
*.audit_file_dest='/u01/app/oracle/admin/orcldb/adump'
*.audit_trail='NONE'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/orcldbstd/controlfile/current.274.980502673'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcldb'
*.db_unique_name='orcldbstd'
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_format='%t_%s_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=300m
*.processes=1000
*.remote_login_passwordfile='exclusive'
*.sga_target=800m
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcldbstd,orcldb)'
*.LOG_ARCHIVE_DEST_1='LOCATION=+data VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcldbstd'
*.LOG_ARCHIVE_DEST_2='SERVICE=orcldb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcldb'
*.log_archive_format='%t_%s_%r.arc'
*.FAL_SERVER='orcldb'
*.fal_client='orcldbstd'
*.DB_FILE_NAME_CONVERT='+DATA/orcldb/datafile/','+DATA/orcldbstd/datafile/','+DATA/orcldb/tempfile/','+DATA/orcldbstd/tempfile/'
*.LOG_FILE_NAME_CONVERT='+DATA/orcldb/onlinelog/','+DATA/orcldbstd/onlinelog/'
*.standby_file_management=AUTO
*.remote_listener='rac-scan-std:1521'
orcldbstd1.instance_number=1
orcldbstd2.instance_number=2
orcldbstd1.thread=1
orcldbstd2.thread=2
orcldbstd1.undo_tablespace='UNDOTBS1'
orcldbstd2.undo_tablespace='UNDOTBS2'
备注:
1、log_archive_dest_1这里写备库arch路径
2、DB_FILE_NAME_CONVERT,LOG_FILE_NAME_CONVERT参数需要已'主库路径','备库路径'一组为准则
3、主库的数据文件路径,日志文件路径需要一一对应到备库(可先查主库所有数据文件的路径)
8、 在备库增加静态监听
[oracle@orcldb:/u01]$vi /u01/app/11.2.0/grid/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME= orcldbstd)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orcldbstd1)
)
)
[grid@rac1-std:/u01/app/11.2.0/grid/network/admin]$srvctl stop listener -n rac1-std
[grid@rac1-std:/u01/app/11.2.0/grid/network/admin]$srvctl start listener -n rac1-std
Service "orcldbstd" has 1 instance(s).
Instance "orcldbstd1", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
9、 启动备库数据库到nomount状态
修改环境变量,设置备库ORACLE_SID,然后启动到nomount
orclstd1
SQL> startup nomount;
10、 主库进入rman,准备使用rman duplicate特性完成备库的部署
在rac其中一个节点执行,连接辅助实例备库1
[oracle@rac1:/home/oracle]$rman target sys/oracle@orcldb1 auxiliary sys/oracle@orcldbstd1
connected to target database: ORCLDB (DBID=2416456206)
connected to auxiliary database: ORCLDB (not mounted)
RMAN>
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate AUXILIARY channel c4 type disk;
allocate AUXILIARY channel c5 type disk;
allocate AUXILIARY channel c6 type disk;
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER
NOFILENAMECHECK;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
}
重要报错:
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 05/03/2019 13:53:38
RMAN-05501: aborting duplication of target database
RMAN-06136: ORACLE error from auxiliary database: ORA-00200: control file could not be created
ORA-00202: control file: '+data'
ORA-17502: ksfdcre:4 Failed to create file +data
ORA-15001: diskgroup "DATA" does not exist or is not mounted
ORA-15040: diskgroup is incomplete
由于oracle可执行文件没有asmadmin权限,要手动更改权限,如下
[oracle@rac1-std:/u01/app/oracle/product/11.2.0/db_1/dbs]$ll $ORACLE_HOME/bin/oracle
-rwsr-s--x 1 oracle oinstall 239520784 May 2 21:42 /u01/app/oracle/product/11.2.0/db_1/bin/oracle
2个授权操作,在两个节点一起进行
[root@rac1-std ~]# chown oracle:asmadmin /u01/app/oracle/product/11.2.0/db_1/bin/oracle
[root@rac1-std ~]# chmod 6751 /u01/app/oracle/product/11.2.0/db_1/bin/oracle
执行过程:
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=60 instance=orcldb1 device type=DISK
allocated channel: c2
channel c2: SID=41 instance=orcldb1 device type=DISK
allocated channel: c3
channel c3: SID=62 instance=orcldb1 device type=DISK
allocated channel: c4
channel c4: SID=35 instance=orcldbstd1 device type=DISK
allocated channel: c5
channel c5: SID=36 instance=orcldbstd1 device type=DISK
allocated channel: c6
channel c6: SID=37 instance=orcldbstd1 device type=DISK
Starting Duplicate Db at 2019-05-03 14:18:11
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldb1' auxiliary format
'/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldbstd1' ;
}
executing Memory Script
Starting backup at 2019-05-03 14:18:12
Finished backup at 2019-05-03 14:18:13
contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '+DATA/orcldbstd/controlfile/current.256.1007302693';
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
''+DATA/orcldbstd/controlfile/current.256.1007302693'' comment=
''Set by RMAN'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
Starting backup at 2019-05-03 14:18:13
channel c1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcldb1.f tag=TAG20190503T141813 RECID=7 STAMP=1007302694
channel c1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2019-05-03 14:18:15
sql statement: create spfile from memory
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 293604432 bytes
Database Buffers 536870912 bytes
Redo Buffers 2371584 bytes
allocated channel: c4
channel c4: SID=33 instance=orcldbstd1 device type=DISK
allocated channel: c5
channel c5: SID=34 instance=orcldbstd1 device type=DISK
allocated channel: c6
channel c6: SID=35 instance=orcldbstd1 device type=DISK
sql statement: alter system set control_files = ''+DATA/orcldbstd/controlfile/current.256.1007302693'' comment= ''Set by RMAN'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 293604432 bytes
Database Buffers 536870912 bytes
Redo Buffers 2371584 bytes
allocated channel: c4
channel c4: SID=33 instance=orcldbstd1 device type=DISK
allocated channel: c5
channel c5: SID=34 instance=orcldbstd1 device type=DISK
allocated channel: c6
channel c6: SID=35 instance=orcldbstd1 device type=DISK
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
RMAN-05529: WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only.
contents of Memory Script:
{
set newname for tempfile 1 to
"+data";
switch clone tempfile all;
set newname for datafile 1 to
"+data";
set newname for datafile 2 to
"+data";
set newname for datafile 3 to
"+data";
set newname for datafile 4 to
"+data";
set newname for datafile 5 to
"+data";
set newname for datafile 6 to
"+DATA/orcldbstd/datafile/admin.dbf";
backup as copy reuse
datafile 1 auxiliary format
"+data" datafile
2 auxiliary format
"+data" datafile
3 auxiliary format
"+data" datafile
4 auxiliary format
"+data" datafile
5 auxiliary format
"+data" datafile
6 auxiliary format
"+DATA/orcldbstd/datafile/admin.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to +data 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
Starting backup at 2019-05-03 14:18:58
channel c1: starting datafile copy
input datafile file number=00003 name=+DATA/orcldb/datafile/undotbs1.271.980502675
channel c2: starting datafile copy
input datafile file number=00001 name=+DATA/orcldb/datafile/system.273.980502673
channel c3: starting datafile copy
input datafile file number=00002 name=+DATA/orcldb/datafile/sysaux.272.980502675
output file name=+DATA/orcldbstd/datafile/undotbs1.258.1007302739 tag=TAG20190503T141858
channel c1: datafile copy complete, elapsed time: 00:00:15
channel c1: starting datafile copy
input datafile file number=00004 name=+DATA/orcldb/datafile/undotbs2.266.980502681
output file name=+DATA/orcldbstd/datafile/system.257.1007302739 tag=TAG20190503T141858
channel c2: datafile copy complete, elapsed time: 00:00:15
channel c2: starting datafile copy
input datafile file number=00006 name=+DATA/orcldb/datafile/admin.dbf
output file name=+DATA/orcldbstd/datafile/sysaux.259.1007302739 tag=TAG20190503T141858
channel c3: datafile copy complete, elapsed time: 00:00:16
channel c3: starting datafile copy
input datafile file number=00005 name=+DATA/orcldb/datafile/users.264.980502681
output file name=+DATA/orcldbstd/datafile/users.262.1007302755 tag=TAG20190503T141858
channel c3: datafile copy complete, elapsed time: 00:00:01
output file name=+DATA/orcldbstd/datafile/undotbs2.260.1007302755 tag=TAG20190503T141858
channel c1: datafile copy complete, elapsed time: 00:00:04
output file name=+DATA/orcldbstd/datafile/admin.dbf tag=TAG20190503T141858
channel c2: datafile copy complete, elapsed time: 00:00:03
Finished backup at 2019-05-03 14:19:17
sql statement: alter system archive log current
contents of Memory Script:
{
backup as copy reuse
archivelog like "+ARCH/orcldb/archivelog/2019_05_03/thread_2_seq_50.290.1007302759" auxiliary format
"+DATA" archivelog like
"+ARCH/orcldb/archivelog/2019_05_03/thread_1_seq_59.289.1007302757" auxiliary format
"+DATA" archivelog like
"+ARCH/orcldb/archivelog/2019_05_03/thread_1_seq_58.288.1007297695" auxiliary format
"+DATA" ;
catalog clone start with "+DATA";
switch clone datafile all;
}
executing Memory Script
Starting backup at 2019-05-03 14:19:23
channel c1: starting archived log copy
input archived log thread=2 sequence=50 RECID=1011 STAMP=1007302759
channel c2: starting archived log copy
input archived log thread=1 sequence=59 RECID=1010 STAMP=1007302757
channel c3: starting archived log copy
input archived log thread=1 sequence=58 RECID=1008 STAMP=1007297694
output file name=+DATA/orcldbstd/archivelog/2019_05_03/thread_2_seq_50.263.1007302765 RECID=0 STAMP=0
channel c1: archived log copy complete, elapsed time: 00:00:01
output file name=+DATA/orcldbstd/archivelog/2019_05_03/thread_1_seq_59.264.1007302765 RECID=0 STAMP=0
channel c2: archived log copy complete, elapsed time: 00:00:01
output file name=+DATA/orcldbstd/archivelog/2019_05_03/thread_1_seq_58.265.1007302765 RECID=0 STAMP=0
channel c3: archived log copy complete, elapsed time: 00:00:01
Finished backup at 2019-05-03 14:19:25
searching for all files that match the pattern +DATA
List of Files Unknown to the Database
=====================================
File Name: +data/orcldbstd/ARCHIVELOG/2019_05_03/thread_2_seq_50.263.1007302765
File Name: +data/orcldbstd/ARCHIVELOG/2019_05_03/thread_1_seq_59.264.1007302765
File Name: +data/orcldbstd/ARCHIVELOG/2019_05_03/thread_1_seq_58.265.1007302765
File Name: +data/orcldbstd/datafile/SYSTEM.257.1007302739
File Name: +data/orcldbstd/datafile/UNDOTBS1.258.1007302739
File Name: +data/orcldbstd/datafile/SYSAUX.259.1007302739
File Name: +data/orcldbstd/datafile/UNDOTBS2.260.1007302755
File Name: +data/orcldbstd/datafile/USERS.262.1007302755
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: +data/orcldbstd/ARCHIVELOG/2019_05_03/thread_2_seq_50.263.1007302765
File Name: +data/orcldbstd/ARCHIVELOG/2019_05_03/thread_1_seq_59.264.1007302765
File Name: +data/orcldbstd/ARCHIVELOG/2019_05_03/thread_1_seq_58.265.1007302765
File Name: +data/orcldbstd/datafile/SYSTEM.257.1007302739
File Name: +data/orcldbstd/datafile/UNDOTBS1.258.1007302739
File Name: +data/orcldbstd/datafile/SYSAUX.259.1007302739
File Name: +data/orcldbstd/datafile/UNDOTBS2.260.1007302755
File Name: +data/orcldbstd/datafile/USERS.262.1007302755
datafile 1 switched to datafile copy
input datafile copy RECID=12 STAMP=1007302765 file name=+DATA/orcldbstd/datafile/system.257.1007302739
datafile 2 switched to datafile copy
input datafile copy RECID=13 STAMP=1007302765 file name=+DATA/orcldbstd/datafile/sysaux.259.1007302739
datafile 3 switched to datafile copy
input datafile copy RECID=14 STAMP=1007302765 file name=+DATA/orcldbstd/datafile/undotbs1.258.1007302739
datafile 4 switched to datafile copy
input datafile copy RECID=15 STAMP=1007302765 file name=+DATA/orcldbstd/datafile/undotbs2.260.1007302755
datafile 5 switched to datafile copy
input datafile copy RECID=16 STAMP=1007302765 file name=+DATA/orcldbstd/datafile/users.262.1007302755
datafile 6 switched to datafile copy
input datafile copy RECID=17 STAMP=1007302765 file name=+DATA/orcldbstd/datafile/admin.dbf
contents of Memory Script:
{
set until scn 2467412;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 2019-05-03 14:19:25
starting media recovery
archived log for thread 1 with sequence 59 is already on disk as file +DATA/orcldbstd/archivelog/2019_05_03/thread_1_seq_59.264.1007302765
archived log for thread 2 with sequence 50 is already on disk as file +DATA/orcldbstd/archivelog/2019_05_03/thread_2_seq_50.263.1007302765
archived log file name=+DATA/orcldbstd/archivelog/2019_05_03/thread_1_seq_59.264.1007302765 thread=1 sequence=59
archived log file name=+DATA/orcldbstd/archivelog/2019_05_03/thread_2_seq_50.263.1007302765 thread=2 sequence=50
media recovery complete, elapsed time: 00:00:00
Finished recover at 2019-05-03 14:19:26
Finished Duplicate Db at 2019-05-03 14:19:33
released channel: c1
released channel: c2
released channel: c3
released channel: c4
released channel: c5
released channel: c6
已完成备库的部署
duplicate之后数据库处于mount状态
11、 在备库上创建spfile文件
ASMCMD> cp /u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcldbstd1.ora spfileorcldbstd.ora
节点1
vi initorcldbstd1.ora
spfile='+data/orcldbstd/spfileorcldbstd.ora'
节点2
vi initorcldbstd2.ora
spfile='+data/orcldbstd/spfileorcldbstd.ora'
rm spfileorcldbstd1.ora
shutdown immediate;
startup mount;
修改集群参数
alter system set cluster_database=true scope=spfile sid='*';
alter system set cluster_database_instances=2 scope=spfile sid='*';
alter system set instance_number=1 scope=spfile sid='orcldbstd1';
alter system set instance_number=2 scope=spfile sid='orcldbstd2';
alter system set thread=1 scope=spfile sid='orcldbstd1';
alter system set thread=2 scope=spfile sid='orcldbstd2';
create undo tablespace UNDOTBS2 datafile '+DATA' size 100M autoextend on;
alter system set undo_tablespace='UNDOTBS2' scope=spfile sid='orcldbstd2';
关闭数据库
shutdown immediate;
12、检查两个节点rac集群参数
local_listener
remote_listener
thread
instance
节点2的local_listener需要改成本地vip
alter system set local_listener='(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.4.134)(PORT=1521))';
13、将备库rac加到集群资源中
srvctl add database -d orcldbstd -n orcldb -o $ORACLE_HOME -p +DATA/orcldbstd/spfileorcldbstd.ora -r physical_standby
srvctl add instance -d orcldbstd -i orcldbstd1 -n rac1-std
srvctl add instance -d orcldbstd -i orcldbstd2 -n rac2-std
srvctl config database -d orcldbstd
14、 打开数据库,备库启用实时应用日志模式
在两个节点打开数据库
SQL> startup;
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
SQL> alter database recover managed standby database using current logfile disconnect;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
只需在其中一个节点,使用实时应用日志模式,另外一个节点打开数据库即可
SQL> select SWITCHOVER_STATUS,DATABASE_ROLE,PROTECTION_MODE,OPEN_MODE FROM v$database;
SWITCHOVER_STATUS DATABASE_ROLE PROTECTION_MODE OPEN_MODE
--------------- ---------------- -------------------- ---------------
NOT ALLOWED PHYSICAL STANDBY MAXIMUM PERFORMANCE READ ONLY WITH APPLY
默认应该为MAXIMIZE PERFORMANCE,备库可启用ADG或者RealTime实时应用日志模式,具体可使用如下步骤。
SQL>startup;
SQL> alter database recover managed standby database cancel;
SQL> alter database recover managed standby database disconnect from session;
SQL> !ps -ef|grep mrp
oracle 22470 1 0 21:51 ? 00:00:00 ora_mrp0_std
MRP进程已启动
查询ADG是否已开启
SQL> SELECT NAME,DATABASE_ROLE,PROTECTION_MODE,OPEN_MODE FROM V$DATABASE;
NAME DATABASE_ROLE PROTECTION_MODE OPEN_MODE
----- -------------------- --------------------------
ORCLDB PHYSICAL STANDBY MAXIMUM PERFORMANCE READ ONLY WITH APPLY
状态“READ ONLY WITH APPLY”即表示此时备库处于Read Only状态的同时可以接受主库传过来的日志进行恢复,以便达到备库可以即时查看到主库变化的目的。
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect;
Database altered.
基于此模式备库会实时与主库数据同步。
SQL> alter database recover managed standby database cancel;
执行完之后MRP进程会停止
SQL> !ps -ef|grep mrp
oracle 22403 21996 0 21:50 pts/1 00:00:00 /bin/bash -c ps -ef|grep mrp
oracle 22405 22403 0 21:50 pts/1 00:00:00 grep mrp
可将备库脱离dataguard环境,成为独立数据库,用于数据库迁移
1、修改备库的pfile
去掉dg环境参数
alter system set LOG_ARCHIVE_CONFIG='' scope=spfile;
alter system reset DB_FILE_NAME_CONVERT scope=spfile;
alter system reset LOG_FILE_NAME_CONVERT scope=spfile;
alter system reset LOG_ARCHIVE_DEST_2 scope=spfile;
alter system set STANDBY_FILE_MANAGEMENT='MANUAL' scope=spfile;
alter system set FAL_SERVER='' scope=spfile;
alter system set FAL_CLIENT='' scope=spfile;
或者修改pfile方式启动
*.audit_file_dest='/u01/app/oracle/admin/orcldb/adump'
*.audit_trail='NONE'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/orcldbstd/controlfile/Current.256.1007302693'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcldb'
*.db_unique_name='orcldbstd'
*.diagnostic_dest='/u01/app/oracle'
*.log_archive_format='%t_%s_%r.arc'
*.open_cursors=300
*.pga_aggregate_target=300m
*.processes=1000
*.remote_login_passwordfile='exclusive'
*.sga_target=800m
*.LOG_ARCHIVE_DEST_1='LOCATION=+data'
*.log_archive_format='%t_%s_%r.arc'
*.remote_listener='rac-scan-std:1521'
orcldbstd1.instance_number=1
orcldbstd2.instance_number=2
orcldbstd1.thread=1
orcldbstd2.thread=2
orcldbstd1.undo_tablespace='UNDOTBS1'
orcldbstd2.undo_tablespace='UNDOTBS2'
再次创建spfile
SQL> create spfile='+DATA/orcldbstd/spfileorcldbstd.ora' from pfile;
重启已spfile启动
2、启动数据库脱离dg环境
SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP
另外一个节点只需startup即可
3、查看数据库状态
SQL> select database_role,switchover_status,open_mode from v$database;
DATABASE_ROLE SWITCHOVER_STATUS OPEN_MODE
---------------- -------------------- --------------------
PRIMARY NOT ALLOWED READ WRITE
已脱离dg
4、测试备库读写
参考MOS ID 2074686.1
1、使用from atcive database时,必须使用密码连接源端和目标端
2、在默认情况duplicate命令并不会应用归档文件对创建的standby数据库数据文件进行恢复,
除非执行duplicate时指定了DORECOVER参数,那么duplicate会传输以及应用所有可应用的redologs。
(active模式下会传输归档到目标端)
在duplicate期间如果不加DORECOVER参数,rman只会还原控制文件,数据文件,不会包含归档日志。等到standby创建完毕之后,才会从primary传输归档到standby。
3、如果是基于backup-based,只需去掉参数FROM ACTIVE DATABASE以及dorecover,把备份文件以及standby控制文件传到目标库,需要保证目标库与源库相同的rman备份目录。
示例:
* 主库RMAN全备
* 创建standby控制文件
主库生成备库standby 控制文件
SQL>alter database create standby controlfile as '/home/oracle/standby.ctl';
* 主库执行命令
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate AUXILIARY channel c4 type disk;
allocate AUXILIARY channel c5 type disk;
allocate AUXILIARY channel c6 type disk;
DUPLICATE TARGET DATABASE
FOR STANDBY;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
}
4、在duplicate传输期间,会将两个节点当前日志序号为起点,之后的归档传输到备库(如rac1 redo当前序号为100,只会传输99之后的归档日志)
5、如果遇到如下报错,说明密码文件在当前节点不存在,可在其中一个节点执行
RMAN-03009: failure of backup command on c1 channel at 07/11/2018 17:15:03
ORA-19505: failed to identify file "/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcldb1"
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
6、standby停库之后,如果再启动还是会从primary端传输redo
7、不能在standby端连接rman
You cannot CONNECT RMAN to the standby database and then use DUPLICATE ... FOR STANDBY to create an additional standby database. To create additional standby databases, connect RMAN to the original primary database and run DUPLICATE ... FOR STANDBY.
Note: Although you can use the DUPLICATE command to create a standby database, you cannot use this command to activate a standby database.
When you connect RMAN to the standby database and the recovery catalog in which the primary database is already registered, RMAN recognizes the standby database and implicitly registers it. Do not attempt to use the REGISTER command for the standby database.
https://docs.oracle.com/cd/B28359_01/backup.111/b28273/rcmsynta020.htm#CHDEDFFH
8、已测试如果源端与目标端数据文件、日志文件目录结构不同,nofilenamecheck参数无区别
9、备库没有standby log无法实时应用日志
SQL> alter database recover managed standby database using current logfile disconnect;
alter database recover managed standby database using current logfile disconnect
*
ERROR at line 1:
ORA-38500: USING CURRENT LOGFILE option not available without standby redo logs
10、当备库作为迁移之目的
a 主库仅需修改如下两个参数,在开启归档模式下无需停机
LOG_ARCHIVE_CONFIG
LOG_ARCHIVE_DEST_2
alter database force logging;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcldb,orcldbstd)' sid='*';
alter system set LOG_ARCHIVE_DEST_2='SERVICE=orcldbstd LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcldbstd' sid='*';
b 备库可不用创建standby redo log
c 如果不考虑主备库的数据同步,主库也可无需修改任何参数,再创建备库
srvctl add database -d orcldbstd -n orcldb -o $ORACLE_HOME -p +DATA/orcldbstd/spfileorcldbstd.ora