【DataGuard安装】Oracle单实例到RAC用duplicate active database做DataGuard之一

时间:2020-11-28 18:25:57


说明

1.源端:(11g单实例)

IP:                      192.168.114.176

Hostname:    vmzj

db_unique_name:         vmzj

 

2.目标端:(11gRAC)

IP:                      192.168.20.241,  192.168,20.242

VIP:                   192.168.20.243,  192.168,20.244

Scan-ip:            192.168.20.245

Hostname:    racnode1,racnode2

db_unique_name:         ru

 

3.此次DG的创建通过duplicate。。。 from active database创建DG

4.数据库版本,两端都是11.2.0.4

另一篇相关文章更为详细一些:Oracle单实例到RAC用duplicate active database做DataGuard之二

源端配置网络

检查确保主库在归档模式

静态监听:

[oracle@vmzj admin]$ vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(PORT = 1522))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=vmzj)
(SID_NAME=vmzj)
(ORACLE_HOME=/u02/oracle/product/11.2.0/dbhome_1)
)
)

网络连接配置

[oracle@vmzj admin]$ vi tnsnames.ora
vmzj =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(host=192.168.114.176)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = vmzj)
)
)

ru =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(host=192.168.20.243)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ru)
)
)

此次只连了集群节点1的vip

 

配置源端参数:

如果使用了MEMORY_TARGET ,必须大于752M

源端必须为归档模式。

SQL>  ALTER DATABASE FORCE LOGGING;

查看主库当前是否为force logging

SQL> select force_logging from v$database;

SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG ='DG_CONFIG=(vmzj,ru)' scope=both;

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_1 ='LOCATION=/u01/arch1/ VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=vmzj'scope=both;

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2 ='SERVICE=ru LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=ru'scope=both;

 

目标端配置

 

在节点1创建初始化参数

[oracle@racnode1 dbs]$ pwd

/u01/apps/oracle/product/11.2.0/dbhome_1/dbs

[oracle@racnode1 dbs]$ vi initvmzj1.ora

db_name=vmzj

 

 

创建密码文件

 

将密码文件从源端拷贝到目标端的节点1.

$ scp orapwvmzjoracle@192.168.20.241:/u01/apps/oracle/product/11.2.0/dbhome_1/dbs/ [oracle@racnode1dbs]$ mv orapwvmzj orapwvmzj1

$ scp orapwvmzj oracle@192.168.20.242:/u01/apps/oracle/product/11.2.0/dbhome_1/dbs/[oracle@racnode2 dbs]$ mv orapwvmzj orapwvmzj2

 

 

最好不要用orapw的创建密码,可能在后面做duplicate时会报如下错误:

[oracle@racnode1 dbs]$ orapwd file=orapwvpassword=oracleentries=10

ORA-17629: Cannot connect to the remotedatabase server

ORA-17627: ORA-01017: invalidusername/password; logon denied

 

 

启动数据到nomount

 

[oracle@racnode1 dbs]$ export ORACLE_SID=vmzj1
[oracle@racnode1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production onTue Nov 18 16:43:27 2014

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 238034944 bytes
Fixed Size 2252016 bytes
Variable Size 180355856 bytes
Database Buffers 50331648 bytes
Redo Buffers 5095424 bytes
SQL>

目标端网络连接配置

以下配置暂时在节点1做了配置,节点2可以现在做,也可以稍后DG完成后再配,方法类似。

目标端静监听配置

 

GRID用户的listener.ora文件新增以下内容

[grid@racnode1 admin]$ vi listener.ora

LISTENER2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(PORT = 1522))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
)
)
SID_LIST_LISTENER2=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=vmzj)
(SID_NAME=vmzj1)
(ORACLE_HOME=/u01/apps/oracle/product/11.2.0/dbhome_1)
)
)
[grid@racnode1admin]$ vi tnsnames.ora
vmzj =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(host=192.168.114.176)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = vmzj)
)
)

ru =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(host=192.168.20.243)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =vmzj)
)
)

 

 

启动该监听                                

[grid@racnode1 admin]$ lsnrctl startlistener2

 

目标端创建必要的文件夹

[oracle@racnode1 ~]$ mkdir -p/u01/apps/oracle/admin/vmzj/adump/

[root@racnode1 u01]# chown -R oracle:dba/u01/oracle

使用duplicate from active database创建DG

 

[oracle@vmzj ~]$ rman target / auxiliarysys/oracle@ru

run {
duplicate target database
for standby
from active database
dorecover
spfile
set"db_unique_name"="ru"
SET LOG_ARCHIVE_DEST_2="service=vmzjASYNC REGISTER
VALID_FOR=(online_logfile,primary_role)"
set fal_server="vmzj"
set control_files='+DATA'
setlog_file_name_convert='/data01/vmzj/VMZJ/onlinelog/','+DATA/'
setdb_file_name_convert='/data01/vmzj/VMZJ/datafile/','+DATA/'
set log_archive_dest_1='LOCATION=+DATA'
set db_recovery_file_dest='+DATA'
set DB_RECOVERY_FILE_DEST_SIZE='3G'
set db_create_file_dest='+DATA'
set cluster_database='true'
set cluster_database_instances='2'
set instance_number='1'
setaudit_file_dest='/u01/apps/oracle/admin/vmzj/adump/'
nofilenamecheck;
}

创建并修改共享的spfile

 

SQL> create pfile from spfile;
删除spfile
SQL> shutdown immediate
Pfile中增加以下内容
vmzj1.instance_number=1
vmzj2.instance_number=2
vmzj1.undo_tablespace='UNDOTBS1'
vmzj2.undo_tablespace='UNDOTBS2'
vmzj1.thread=1
vmzj2.thread=2

SQL> startup
SQL> select open_mode from V$database;

OPEN_MODE
--------------------
READ ONLY
SQL> create spfile='+DATA' from pfile;
SQL> shutdown immediate

查看spfile的路径:

ASMCMD> pwd

+DATA/RU/PARAMETERFILE

ASMCMD> ls

spfile.264.864212629

将库注册到srvctl

[oracle@racnode1 ~]$ srvctl add database -dru -o /u01/apps/oracle/product/11.2.0/dbhome_1 -p+DATA/RU/PARAMETERFILE/spfile.264.864212629

[oracle@racnode1 ~]$ srvctl add instance -dru -i vmzj1 -n racnode1

[oracle@racnode1 ~]$ srvctl add instance -dru -i vmzj2 -n racnode2

[oracle@racnode1 ~]$ srvctl status database-d ru

Instance vmzj1 is not running on noderacnode1

Instance vmzj2 is not running on noderacnode2

需要在节点2上添加以下目录

[root@racnode2 ~]# mkdir -p /u01/oracle

[root@racnode2 ~]# chown -R oracle:dba/u01/oracle

启动数据库

[oracle@racnode1 ~]$ srvctl start database-d ru

[oracle@racnode1 ~]$ srvctl status database-d ru

Instance vmzj1 is running on node racnode1

Instance vmzj2 is running on node racnode2 

启动DG的apply。

SQL> select open_mode from V$database;

OPEN_MODE
--------------------
READ ONLY
SQL> alter database recover managedstandby database disconnect from session;

Database altered.

SQL> select open_mode from V$database;

OPEN_MODE
--------------------
READ ONLY WITH APPLY
切换log测试:

备库查看目前Log应用的状态

SQL> select sequence#,applied from V$archived_log
2 order by sequence#;

SEQUENCE#APPLIED
---------- ---------
58 YES
59 YES

主库切换日志

SQL> alter system switch logfile;

备库查看

SQL> select sequence#,applied from V$archived_log
order by sequence#;

SEQUENCE# APPLIED
---------- ---------
58 YES
59 YES
60 YES
61 YES
62 YES
63 YES
64 YES

7 rows selected.