前言
oracle data guard是oracle maa(maximum availability architecture)中的成员之一。从oracle 7i版本开始推出standby database的概念,慢慢受到大家的欢迎。随着oracle数据库版本的更迭,搭建备库的方式多种多样。今天介绍一种创建物理备库的新方式,从12c版本开始推出:使用 dbca 命令行。
dbca -createduplicatedb -createasstandby -dbuniquename
优缺点:方便快捷,搭建速度较快。但是会影响主库的性能,执行过程报错不方便排查。
具体命令可参考:
1
2
3
4
5
6
7
|
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环境一键安装:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
./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软件,不建库)
1
|
./oracleshellinstall.sh -i 10.211.55.110 -n dbca_stby -o cdb19c -opa 32545013 -w y
|
二、adg搭建准备
a.配置hosts文件
主库:
1
2
3
4
5
|
cat <<eof >> /etc/hosts
## for dg begin
10.211.55.110 dbca_stby
## for dg end
eof
|
备库:
1
2
3
4
5
6
7
|
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
1
2
3
4
5
6
7
8
9
10
11
12
|
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
1
2
3
4
5
6
7
8
9
10
11
12
|
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
|
备库
1
2
3
4
5
6
7
8
9
10
11
12
|
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
|
重启监听
1
2
3
4
5
6
|
#主库rac重启监听
srvctl stop listener
srvctl start listener
##备库重启监听
lsnrctl start
|
tnsnames.ora增加tns:
oracle用户执行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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测试连通性:
1
2
3
4
|
tnsping cdb19c
tnsping cdb19c1
tnsping cdb19c2
tnsping cdb19c_stby
|
c.主库配置参数
1
2
3
4
5
|
sql> select force_logging,log_mode,cdb from gv$ database ;
force_logging log_mode cdb
---------------------------------------
yes archivelog yes
|
如果没有开启强制日志:
1
|
alter database force logging;
|
如果没有开启归档日志:
1
2
3
4
5
|
shutdown immediate
startup mount
alter database archivelog;
alter database open ;
alter pluggable database all open ;
|
d.主库添加stanby log文件
1
2
3
|
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
2
3
4
5
6
7
8
9
10
11
12
13
14
|
--需要注意:
--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;
|
1
|
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用户执行:
1
2
3
4
5
6
7
8
9
|
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参数
1
2
3
4
5
6
7
8
9
10
11
|
--主库设置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='*'
,修改多个实例。
1
2
3
4
5
6
7
8
9
10
11
|
--备库设置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参数配置:
1
|
show parameter db_create_file_dest
|
注意:如果同时设置omg和db_file_name_convert参数,则优先omf参数。
五、开启日志应用
1
2
3
4
5
|
##备库执行
alter database recover managed standby database using current logfile disconnect from session;
##主库执行
alter system set log_archive_dest_state_2=enable sid= '*' ;
|
六、测试同步
主库创建测试数据:
1
|
alter session set container=orcl;
|
1
|
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的资料请关注服务器之家其它相关文章!
原文链接:https://blog.csdn.net/m0_50546016/article/details/117607801