数据库管理-第141期 DG PDB - Oracle DB 23c(20240129)
使用DG PDB初始化搭建还是比较繁琐的,但是不需要全量CDB级别同步数据,还是比较方便,切换也很方便。
数据库管理141期 2024-01-29
第141期 DG PDB - Oracle DB 23c(20240129)
作者:胖头鱼的鱼缸(尹海文)
Oracle ACE Associate: Database(Oracle与MySQL)
网思科技 DBA总监
10年数据库行业经验,现主要从事数据库服务工作
拥有OCM 11g/12c/19c、MySQL 8.0 OCP、Exadata、CDP等认证
墨天轮MVP、认证技术专家,ITPUB认证专家,OCM讲师
圈内拥有“总监”、“保安”、“国产数据库最大敌人”等称号,非著名社恐(社交恐怖分子)
公众号:胖头鱼的鱼缸;CSDN:胖头鱼的鱼缸(尹海文);墨天轮:胖头鱼的鱼缸;ITPUB:yhw1809。
除授权转载并标明出处外,均为“非法”抄袭。
首先,这应该是我一月份最后一片文章了(不保证),本期回归一下技术,重新转头把去年Oracle 23c系列文章中高可用这部分的坑给填了,深入捯饬一下DG PDB。
1 概念
从Oracle DB 23c开始,引入了DG PDB,即在原来CDB级别DG的基础上,增加了PDB级别的DG,这种配置下CDB彻底沦为PDB的底座,PDB可以在任意CDB之间构建DG架构而不用考虑CDB的角色问题;相较于21c的功能,现在PDB备库可以为只读状态了。
DG PDB的好处可以充分利用主备端的硬件资源,让每个CDB都能承载生产PDB和灾备PDB。
2 环境说明
这里选择了最新版本的Oracle Linux9.3作为操作系统,俩CDB均已开启归档模式:
本次操作会根据实际情况进行,其中pdbprod1将在对端做DG PDB。
3 操作
3.1 数据库配置
俩CDB均执行:
alter system set dg_broker_start=true;
alter system set standby_file_management=auto;
alter database flashback on;
prodcdb:
alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prodcdb' scope=both;
proddg:
alter system set log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=proddg' scope=both;
俩CDB需要使用同样的密码文件。
3.2 配置tnsname
/u01/app/oracle/product/23.0.0/dbhome_1/network/admin/tnsnames.ora
PRODCDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = prodcdb)
)
)
PRODDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.201)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = proddg)
)
)
3.3 配置强制日志
alter database force logging;
3.4 DG配置
dgmgrl sys/oracle@prodcdb
dgmgrl>
CREATE CONFIGURATION 'dgconf_1' AS PRIMARY DATABASE IS 'prodcdb' CONNECT IDENTIFIER IS prodcdb;
dgmgrl sys/oracle@proddg
dgmgrl>
CREATE CONFIGURATION 'dgconf_2' AS PRIMARY DATABASE IS 'proddg' CONNECT IDENTIFIER IS proddg;
3.5 DG配置建立联系
dgmgrl sys/oracle@prodcdb
dgmgrl>
ADD CONFIGURATION 'dgconf_2' CONNECT IDENTIFIER IS proddg;
show configuration;
dgmgrl sys/oracle@proddg
dgmgrl>
show configuration;
3.6 启用所有DG配置
dgmgrl sys/oracle@prodcdb
dgmgrl>
enable configuration all;
show configuration;
dgmgrl sys/oracle@proddg
dgmgrl>
show configuration;
3.7 启用DG PDB
dgmgrl sys/oracle@prodcdb
dgmgrl>
EDIT CONFIGURATION PREPARE DGPDB;
3.8 创建源PDB的DG配置
dgmgrl sys/oracle@proddg
dgmgrl>
add pluggable database pdbdg1 at proddg source is pdbprod1 at prodcdb PDBFileNameConvert is "'/u01/app/oracle/oradata/PRODCDB','/u01/app/oracle/oradata/PRODDG'";
3.9 拷贝pdbprod1文件至proddg
prodcdb:
alter session set container=pdbprod1;
alter database begin backup;
scp -r /u01/app/oracle/oradata/PRODCDB/100D0E78F6B3C90AE063650A0A0ACA90/ db23cdg:/u01/app/oracle/oradata/PRODDG/
prodcdb:
alter session set container=pdbprod1;
alter database end backup;
这里同样可以使用rman duplicate pluggable database来复制文件,这里不做演示。
3.10 目标PDB添加standby log
alter session set container=pdbdg1;
alter database add standby logfile size 200m;
alter database add standby logfile size 200m;
alter database add standby logfile size 200m;
alter database add standby logfile size 200m;
3.11 验证并启动DG PDB
dgmgrl sys/oracle@proddg
dgmgrl>
VALIDATE PLUGGABLE DATABASE pdbdg1 at proddg;
dgmgrl sys/oracle@proddg
dgmgrl>
edit PLUGGABLE DATABASE pdbdg1 at proddg set state='APPLY-ON';
show configuration;
show pluggable database pdbdg1 at proddg;
show pluggable database pdbprod1 at prodcdb;
3.12 切换PDB角色
dgmgrl sys/oracle@proddg
dgmgrl>
VALIDATE PLUGGABLE DATABASE pdbdg1 at proddg;
switchover to pluggable database pdbdg1 at proddg;
这时候新的备库会出现异常,因为没有添加standby log,需要处理。
3.13 源库PDB添加standby log
dgmgrl sys/oracle@proddg
dgmgrl>
edit PLUGGABLE DATABASE pdbprod1 at prodcdb set state='APPLY-OFF';
alter session set container=pdbprod1;
alter database add standby logfile size 200m;
alter database add standby logfile size 200m;
alter database add standby logfile size 200m;
alter database add standby logfile size 200m;
dgmgrl sys/oracle@proddg
dgmgrl>
edit PLUGGABLE DATABASE pdbprod1 at prodcdb set state='APPLY-ON';
show pluggable database pdbprod1 at prodcdb;
3.14 开启备库查询
alter session set container=pdbprod1;
alter pluggable database open;
dgmgrl>
show pluggable database pdbprod1 at prodcdb;
3.15 回切测试
dgmgrl>
switchover to pluggable database pdbprod1 at prodcdb;
show pluggable database pdbprod1 at prodcdb;
show pluggable database pdbdg1 at proddg;
show configuration;
至此DG PDB搭建完成。
总结
使用DG PDB初始化搭建还是比较繁琐的,但是不需要全量CDB级别同步数据,还是比较方便,切换也很方便。
老规矩,知道写了些啥。
参考文档:Scenarios for Using DGMGRL with a DG PDB Configuration (23c)(ttps://docs.oracle.com/en/database/oracle/oracle-database/23/dgbkr/scenarios-using-dgmgrl-dg-pdb-configuration-23c.html)
更多推荐
所有评论(0)