DBCA命令行搭建Oracle ADG的流程

叶子小小的,碧绿碧绿的,花儿小小的,好可爱。紫红色的玫瑰花在风中翩翩起舞,玫瑰花树枝上还有调皮又可爱的小刺,你可要当心哦!你看,那个大仙人球旁围着8个小仙人球,好像一家人聚在一起,多欢快呀!

前言

Oracle Data Guard是Oracle MAA(Maximum Availability Architecture)中的成员之一。从Oracle 7i版本开始推出STANDBY DATABASE的概念,慢慢受到大家的欢迎。随着Oracle数据库版本的更迭,搭建备库的方式多种多样。今天介绍一种创建物理备库的新方式,从12C版本开始推出:使用 DBCA 命令行。

dbca -createDuplicateDB -createAsStandby -dbUniqueName

优缺点:方便快捷,搭建速度较快。但是会影响主库的性能,执行过程报错不方便排查。

具体命令可参考:

dbca -silent -createDuplicateDB
    -gdbName global_database_name
    -primaryDBConnectionString easy_connect_string_to_primary
    -sid database_system_identifier
    [-createAsStandby 
        [-dbUniqueName db_unique_name_for_standby]]
    [-customScripts scripts_list]

更详细参数可参考:The createDuplicateDB command creates a duplicate of an Oracle database.

12.2.0.1开始支持DBCA创建物理备库:

主库必须是单机环境,非RAC数据库。

主库必须是非CDB环境。

18c之后,以上限制已经取消,支持主库是CDB和RAC环境。

一、环境准备

环境安装过程忽略,可参考:

30分钟!一键部署Oracle 19C单机CDB+PDB

本次测试尽量按照生产环境升级进行模拟:

节点 主机版本 主机名 实例名 Oracle版本 IP地址
rac01 rhel7.9 rac01 cdb19c 19.3.0(补丁 29585399) 10.211.55.100
rac02 rhel7.9 rac02 orcl+cdb19c 19.3.0(补丁 29585399) 10.211.55.101
备库 rhel7.9 dbca_stby 不创建实例 19.3.0(补丁 29585399) 10.211.55.110

注意:

1、db_unique_name主备库不能相同。

2、db_name主备库需保持一致。

3、主备库DB版本需保持一致。

Oracle测试环境安装:

可参考:DBA运维福音:10分钟,Linux一行命令安装Oracle数据库

主库RAC环境一键安装:

./OracleShellInstall.sh -i 10.211.55.100 `#Public ip`\
-n rac `# hostname`\
-c TRUE `# cdb`\
-pb orcl `# pdb`\
-o cdb19c `# oraclesid`\
-rs oracle `# root password`\
-op oracle `# oracle password`\
-gp oracle `# grid password`\
-b /u01/app `# install basedir`\
-s AL32UTF8 `# characterset`\
-pb1 10.211.55.100 -pb2 10.211.55.101 `# node public ip`\
-vi1 10.211.55.102 -vi2 10.211.55.103 `# node virtual ip`\
-pi1 1.1.1.1 -pi2 1.1.1.2 `# node private ip`\
-si 10.211.55.105 `# scan ip`\
-dd /dev/sdc `# asm data disk`\
-od /dev/sdb `# asm ocr disk`\
-or EXTERNAL `# asm ocr redundancy`\
-dr EXTERNAL `# asm data redundancy`\
-on OCR `# asm ocr diskgroupname`\
-dn DATA `# asm data diskgroupname`\
-puf eth0 -prf eth1 `# network fcname`\
-tsi 10.211.55.200 `# timeserver`\
-gpa 32545008 `# Grid PSU NUMBER`

备库一键安装:(备库仅安装ORACLE软件,不建库)

./OracleShellInstall.sh -i 10.211.55.110 -n dbca_stby -o cdb19c -opa 32545013 -w Y

二、ADG搭建准备

a.配置hosts文件

主库:

cat <<EOF >> /etc/hosts
##FOR DG BEGIN
10.211.55.110 dbca_stby
##FOR DG END
EOF

备库:

cat <<EOF >> /etc/hosts
##FOR DG BEGIN
10.211.55.100 rac01
10.211.55.101 rac02
10.211.55.105 rac-scan
##FOR DG END
EOF

b.配置静态监听和TNS

listener.ora增加静态监听:

grid用户执行:

rac01

cat <<EOF >> $TNS_ADMIN/listener.ora
##FOR DG BEGIN
SID_LIST_LISTENER =
	(SID_LIST =
		(SID_DESC =
			(GLOBAL_DBNAME = cdb19c)
			(ORACLE_HOME = /u01/app/oracle/product/19.3.0/db)
			(SID_NAME = cdb19c1)
		)
	)
##FOR DG END
EOF

rac02

cat <<EOF >> $TNS_ADMIN/listener.ora
##FOR DG BEGIN
SID_LIST_LISTENER =
	(SID_LIST =
		(SID_DESC =
			(GLOBAL_DBNAME = cdb19c)
			(ORACLE_HOME = /u01/app/oracle/product/19.3.0/db)
			(SID_NAME = cdb19c2)
		)
	)
##FOR DG END
EOF

备库

cat <<EOF >>$TNS_ADMIN/listener.ora
##FOR DG BEGIN
SID_LIST_LISTENER =
(SID_LIST =
	(SID_DESC =
		(GLOBAL_DBNAME = cdb19c_stby)
		(ORACLE_HOME = /u01/app/oracle/product/19.3.0/db)
		(SID_NAME = cdb19c_stby)
	)
)
##FOR DG END
EOF

重启监听

#主库RAC重启监听
srvctl stop listener
srvctl start listener

##备库重启监听
lsnrctl start

tnsnames.ora增加TNS:

oracle用户执行:

cat <<EOF >> $TNS_ADMIN/tnsnames.ora
##FOR DG BEGIN
CDB19C =
(DESCRIPTION =
	(ADDRESS_LIST =
		(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
	)
	(CONNECT_DATA =
		(SERVICE_NAME = cdb19c)
	)
)
CDB19C1 =
(DESCRIPTION =
	(ADDRESS_LIST =
		(ADDRESS = (PROTOCOL = TCP)(HOST = rac01)(PORT = 1521))
	)
	(CONNECT_DATA =
		(SERVICE_NAME = cdb19c)
	)
)
CDB19C2 =
(DESCRIPTION =
	(ADDRESS_LIST =
		(ADDRESS = (PROTOCOL = TCP)(HOST = rac02)(PORT = 1521))
	)
	(CONNECT_DATA =
		(SERVICE_NAME = cdb19c)
	)
)
CDB19C_STBY =
(DESCRIPTION =
	(ADDRESS_LIST =
		(ADDRESS = (PROTOCOL = TCP)(HOST = dbca_stby)(PORT = 1521))
	)
	(CONNECT_DATA =
		(SERVICE_NAME = cdb19c_stby)
	)
)
##FOR DG BEGIN
EOF

tnsping测试连通性:

tnsping cdb19c
tnsping cdb19c1
tnsping cdb19c2
tnsping cdb19c_stby

c.主库配置参数

SQL> select force_logging,log_mode,cdb from gv$database;

FORCE_LOGGING		LOG_MODE     CDB
--------------------------------------- 
YES					ARCHIVELOG   YES

如果没有开启强制日志:

alter database force logging;

如果没有开启归档日志:

shutdown immediate
startup mount
alter database archivelog;
alter database open;
alter pluggable database all open;

d.主库添加stanby log文件

set line222
col member for a60
select t2.thread#,t1.group#,t1.member,t2.bytes/1024/1024 from v$logfile t1,v$log t2 where t1.group#=t2.group# order by 1,2;

--需要注意:
--1.stanby log日志大小至少要和redo log日志一样大小,不能小于
--2.stanby log数量: standby logfile=(1+logfile组数)=(1+2)=3组,每个thread需要加3组standby logfile.
--3.thread要与redo log保持一致,如果是rac,需要增加多个thread对应的standby log

ALTER DATABASE ADD STANDBY LOGFILE thread 1 
group 5 ('+DATA') SIZE 120M,
group 6 ('+DATA') SIZE 120M,
group 7 ('+DATA') SIZE 120M;

ALTER DATABASE ADD STANDBY LOGFILE thread 2
group 8 ('+DATA') SIZE 120M,
group 9 ('+DATA') SIZE 120M,
group 10 ('+DATA') SIZE 120M;

select t2.thread#,t1.group#,t1.member,t2.bytes/1024/1024 from v$logfile t1,v$standby_log t2 where t1.group#=t2.group# order by 1,2;

三、DBCA创建物理备库

oracle用户执行:

dbca -silent -createDuplicateDB \
-gdbName cdb19c \
-sid cdb19c \
-sysPassword oracle \
-primaryDBConnectionString 10.211.55.105:1521/cdb19c \
-nodelist dbca_stby \
-databaseConfigType SINGLE \
-createAsStandby -dbUniqueName cdb19c_stby \
-datafileDestination '/oradata'

DBCA物理DG创建成功。

四、配置主库+备库DG参数

--主库设置DG参数
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(CDB19C,CDB19C_STBY)' sid='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=+DATA VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=CDB19C' sid='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=cdb19c_stby ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=CDB19C_STBY' sid='*';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE sid='*';
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4 sid='*';
ALTER SYSTEM SET FAL_SERVER=CDB19C_STBY sid='*';
ALTER SYSTEM SET FAL_CLIENT=CDB19C sid='*';
ALTER SYSTEM SET DB_FILE_NAME_CONVERT='+DATA','/oradata/CDB19C_STBY' SCOPE=SPFILE sid='*';
ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='+DATA','/oradata/CDB19C_STBY' SCOPE=SPFILE sid='*';
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO sid='*';

注意:RAC修改参数需要加上 sid='*',修改多个实例。

--备库设置DG参数
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(CDB19C_STBY,CDB19C)';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=CDB19C_STBY';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=CDB19C ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=CDB19C';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4;
ALTER SYSTEM SET FAL_SERVER=CDB19C;
ALTER SYSTEM SET FAL_CLIENT=CDB19C_STBY;
ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/oradata/CDB19C_STBY','+DATA' SCOPE=SPFILE;
ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/oradata/CDB19C_STBY','+DATA' SCOPE=SPFILE;
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

查看OMF参数配置:

show parameter db_create_file_dest

注意:如果同时设置OMG和DB_FILE_NAME_CONVERT参数,则优先OMF参数。

五、开启日志应用

##备库执行
alter database recover managed standby database using current logfile disconnect from session;

##主库执行
alter system set log_archive_dest_state_2=enable sid='*';

六、测试同步

主库创建测试数据:

alter session set container=orcl;

sqlplus lucifer/lucifer@orcl

备库查看是否同步:

至此,ADG已搭建完毕。感谢食用~

参考文章:

官方文档12c:Using DBCA to Create a Data Guard Standby 12C

官方文档19c:Using DBCA to Create a Data Guard Standby 19C

官方文档21c:Using DBCA to Create a Data Guard Standby 21C

MOS文档:Creating a Physical Standby database using DBCA duplicate (Doc ID 2283697.1)

以上就是DBCA搭建Oracle ADG的详细内容,更多关于DBCA搭建Oracle ADG的资料请关注其它相关文章!

标签: 命令行 DBCA