代码改变世界

在多租户(容器)数据库中如何创建PDB:方法4 克隆远程Non-CDB

2019-08-19 13:57  askscuti  阅读(752)  评论(0编辑  收藏  举报

基于版本:19c (12.2.0.3) AskScuti

创建方法:克隆远程Non-CDB(从 Non-CDB 中进行远程克隆)。将 非CDB数据库PROD1 远程克隆为 CDB1 中的 PDB7

对应路径:Creating a PDB --> Cloning --> Remotely --> From a Non-CDB

 在容器数据库CDB里面如何创建PDB,官方文档给出了一张创建PDB技术选项图,图片如下:

内容总览

1. 概述

2. 源数据库PROD1设置只读

3. 编辑TNSNAMES.ora

4. 创建DBLINK

5. 远程克隆PROD1

6. 执行noncdb_to_pdb.sql脚本

7. 打开PDB7

 

1. 概述

克隆远程Non-CDB的意思是指:被克隆的源数据库为非CDB数据库(12c之前版本称之为 Non-CDB),通过DBLink方式进行克隆。

 

2. 源数据库PROD1设置只读

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1241513488 bytes
Fixed Size             8896016 bytes
Variable Size         318767104 bytes
Database Buffers      905969664 bytes
Redo Buffers            7880704 bytes
Database mounted.
SQL> alter database open read only;

Database altered.

 

3. 编辑TNSNAMES.ora

PROD1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.14)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = PROD1)
    )
  )

 

4. 创建DBLINK

SQL> create database link link_prod1 connect to system identified by oracle using 'PROD1';

Database link created.

 

5. 远程克隆PROD1

SQL> create pluggable database pdb7 from NON$CDB@link_prod1 create_file_dest='/u01/app/oracle/oradata/CDB1/pdb7';

Pluggable database created.

如果报错如下:

SQL> create pluggable database pdb7 from NON$CDB@link_prod1 create_file_dest='/u01/app/oracle/oradata/CDB1/pdb7';
create pluggable database pdb7 from NON$CDB@link_prod1 create_file_dest='/u01/app/oracle/oradata/CDB1/pdb7'
*
ERROR at line 1:
ORA-17628: Oracle error 1031 returned by remote Oracle server
ORA-01031: insufficient privileges

到源数据库里面针对PROD1数据库,授权SYSTEM用户 create pluggable database 权限即可。

SQL> shutdown immediate;
SQL> startup;
SQL> select * from dba_sys_privs where GRANTEE='SYSTEM';

GRANTE PRIVILEGE                ADM COM INH
------ ------------------------ --- --- ---
SYSTEM GLOBAL QUERY REWRITE     NO  YES YES
SYSTEM CREATE TABLE             NO  YES YES
SYSTEM DEQUEUE ANY QUEUE        YES YES YES
SYSTEM ENQUEUE ANY QUEUE        YES YES YES
SYSTEM SELECT ANY TABLE         NO  YES YES
SYSTEM MANAGE ANY QUEUE         YES YES YES
SYSTEM UNLIMITED TABLESPACE     NO  YES YES
SYSTEM CREATE MATERIALIZED VIEW NO  YES YES

SQL> grant create pluggable database to system;

Grant succeeded.

SQL> select * from dba_sys_privs where GRANTEE='SYSTEM';

GRANTE PRIVILEGE                ADM COM INH
------ ------------------------- --- --- ---
SYSTEM CREATE PLUGGABLE DATABASE NO  NO  NO
SYSTEM GLOBAL QUERY REWRITE      NO  YES YES
SYSTEM CREATE TABLE              NO  YES YES
SYSTEM DEQUEUE ANY QUEUE         YES YES YES
SYSTEM ENQUEUE ANY QUEUE         YES YES YES
SYSTEM SELECT ANY TABLE          NO  YES YES
SYSTEM MANAGE ANY QUEUE          YES YES YES
SYSTEM UNLIMITED TABLESPACE      NO  YES YES
SYSTEM CREATE MATERIALIZED VIEW  NO  YES YES

SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database open read only;

Database altered.

 

6. 执行noncdb_to_pdb.sql脚本

SQL> alter session set container=pdb7;

SQL> @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

 

 7. 打开PDB7

SQL> alter pluggable database pdb7 open;

Pluggable database altered.