当前位置:网站首页>利用ADG Standby克隆PDB
利用ADG Standby克隆PDB
2022-06-12 21:30:00 【dingdingfish】
本文参考了文章:How to Clone a PDB from a Standby Database in a Data Guard Environment,并完成了整个实验过程。
首先需要一个ADG的环境,比较好的方式是用Oracle Vagrant Projects的OracleDG项目。
这个项目会创建1主1备的ADG环境,版本为19.3。基于64GB内存,4 OCPU的宿主机,创建时间30分钟左右,非常快。
在数据库备机上再创建一个CDB,用来承载克隆的PDB。用dbca静默模式创建,时间在22分钟左右。
目前的架构如下,PDB1是需要克隆的库:
上面标准的DB193H1和DB193H1_STDBY是DB_UNIQUE_NAME,实际的数据库名为DB193H1。
为了表述清楚,后续我们将DB193H1称为主库,DB193H1_STDBY称为备库,ORCLCDB2称为测试库。
首先,我们需要将备库改为只读状态:
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 ORCLPDB1 MOUNTED
SQL> alter pluggable database orclpdb1 open read only;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 ORCLPDB1 READ ONLY NO
正是由于备库最多只能为只读,因此我们才需要额外建立一个数据库来承载克隆出来的PDB。如果直接用备库上的CDB来作为克隆的目标容器,则会报错如下:
SQL> create pluggable database PDBCLONE from ORCLPDB1;
create pluggable database PDBCLONE from ORCLPDB1
*
ERROR at line 1:
ORA-16000: database or pluggable database open for read-only access
我们在主库上创建一个克隆管理员clone_admin,是common user,后续将通过他来做克隆操作,此用户建立后会通过ADG传播到备库。
create user c##clone_admin identified by Welcome1;
grant create session, resource to c##clone_admin container=all;
grant create pluggable database to c##clone_admin container=all;
grant sysoper to c##clone_admin container=all;
alter user c##clone_admin set container_data=ALL container=current;
grant select on cdb_pdbs to c##clone_admin;
-- 在参考文档1中,使用了另一种方法,但我没有试过
grant create session, sysoper to C##SYSOPER identified by SysOperPw__199 container=all;
然后在测试库上建立Database link,注意,此Database link是指向备库而非主库,目的是为了减轻对主库的影响,以及避免网络的延迟。
SQL> create public database link clone_link connect to c##clone_admin identified by Welcome1 using 'DB193H1_STDBY';
SQL> select pdb_name from cdb_pdbs@clone_link;
PDB_NAME
--------------------------------------------------------------------------------
PDB1
PDB$SEED
目前我们的备库(克隆的源库)状态如下:
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB1 READ WRITE NO
目前我们的测试库(克隆的目标库)状态如下:
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
在测试库中启动克隆:
SQL> create pluggable database PDBCLONE from PDB1@clone_link;
create pluggable database PDBCLONE from PDB1@clone_link
*
ERROR at line 1:
ORA-00600: internal error code, arguments: [3647], [19], [16400], [], [], [],
[], [], [], [], [], []
好了,这正是我们期待的错误。因为是从备库克隆,所以会出现此错误。如果从主库克隆,则不会出错,但这并不是我们今天测试的场景。
MOS的这篇文档Create Pluggable Database From ADG errors out with ORA-600 [3647] (Doc ID 2072550.1),详细介绍了原因和解决方法。这篇文档的适用数据库版本范围为12.1.0.2 to 21.1。
简单来说,解决方法是先需要停止redo apply再做克隆,克隆完成后,即可启动redo apply。
注意,上一个克隆虽然失败,但是仍然产生了一个PDB的条目,我们需要先删除他:
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBCLONE MOUNTED
SQL> drop pluggable database PDBCLONE including datafiles;
Pluggable database dropped.
可以在数据库或DGMGRL中停止redo apply:
-- 数据库中
alter database recover managed standby database cancel ;
-- DGMGRL中
edit database db193h1_stdby set state = 'apply-off';
这一回成功了:
SQL> create pluggable database PDBCLONE from PDB1@clone_link;
Pluggable database created.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
4 PDBCLONE MOUNTED
SQL> alter pluggable database pdbclone open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
4 PDBCLONE READ WRITE NO
现在可以恢复redo apply了:
-- 数据库中
alter database recover managed standby database disconnect ;
-- DGMGRL中
edit database db193h1_stdby set state = 'apply-on';
为了进一步确认,我又在主库中安装了Sample Schema,重复以上过程,数据确实克隆到测试库了。
以下是几点说明:
- 原文中最后一张图,清晰的说明了执行操作的顺序以及在何处执行。其中对于备库中的PDB,是先stop redo apply,然后open readonly; 执行完克隆后,是先close PDB(克隆源),然后再start redo apply。我虽然没有执行close的动作也成功了,但还是按照他的流程来。
- Refreshable PDB 克隆不支持基于ADG standby创建,这个就不试了。详见Doc ID 2765472.1
参考
边栏推荐
- NIO使用指南
- Ubuntu16.04 completely delete MySQL database
- ASCII code comparison table
- Research Report on market supply and demand and strategy of hydraulic operating table industry in China
- Redis cluster mget optimization
- RestTemplate的@LoadBalance注解
- Graphics2d class basic use
- torch. unique()
- The salted fish has been transmitted for 5W times, and the latest spring recruit face-to-face test questions of bytes have been leaked
- 杨辉三角代码实现
猜你喜欢
NPOI 创建Word
Risk control modeling X: Discussion on problems existing in traditional modeling methods and Exploration on improvement methods
GNS安装与配置
Smart management of green agriculture: a visual platform for agricultural product scheduling
What are the disadvantages of bone conduction earphones? Analysis of advantages and disadvantages of bone conduction earphones
测试基础之:单元测试
nn. PReLU(planes)
GNS installation and configuration
【目标检测】|Dive Deeper Into Box for Object Detection 基于FCOS新训练方法
Lombok package is successfully installed, but the runtime prompts that get, set method and constructor solution cannot be found
随机推荐
leetcode:210. 課程錶 II
torch. unique()
Shell language
The Post-00 financial woman with a monthly salary of 2W conquered the boss with this set of report template
字符串基础知识
(4) Pyqt designs and implements the [factory production management system] order page - add, delete, modify and query (including source code analysis)
Zip压缩解压缩
Data visualization - histogram
Can flush open an account? Can you directly open the security of securities companies on the app
Solve one-dimensional array prefix sum
The year of the outbreak of financial innovation! All dtinsight products of kangaroo cloud data stack have passed the special test of Xinchuang of ICT Institute
Test basis: unit test
Research Report on market supply and demand and strategy of China's hydraulic injection molding machine industry
Pytoch distributed training error
NIO使用指南
makefile 的ifeq,filter,strip 简单使用
Access control system based on RFID
leetcode:210. 课程表 II
China hydraulic press market trend report, technical innovation and market forecast
leetcode:207. Class Schedule Card