签到成功

知道了

CNDBA社区CNDBA社区

Orcle 12c 新特性---PDB Subset Cloning

2017-08-14 09:20 2037 0 原创 Oracle 12C
作者: Expect-乐

说明

12.1.0.2开始,引入了User Tablespaces,简单的说就是可以按表空间(用户创建的)来克隆PDB。比如,当前PDB1中,用户新建了三个表空间tbs1,tbs2,tbs3,那么我们后期测试,可能只需要tbs1表空间中的数据,那么我们可以用USER_TABLESPACES子句来只克隆PDB1中的tbs1表空间,这样大大的缩短了可怜时间和不必要的空间开销。对于拆分数据也很有用,可以把一个库按照表空间拆分。

USER_TABLESPACES子句支持四种参数:

1.  List one or more tablespaces to include.

http://www.cndba.cn/Expect-le/article/2103

2.  Specify ALL, the default, to include all of the tablespaces.

http://www.cndba.cn/Expect-le/article/2103

3.  Specify ALL EXCEPT to include all of the tablespaces, except for the tablespaces listed.

4.  Specify NONE to exclude all of the tablespaces.http://www.cndba.cn/Expect-le/article/2103

实验

2.1   环境

当前环境有LEI1PDB

SQL> show pdbs;
    CON_ID CON_NAME	  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
 3 LEI1   READ WRITE NO

http://www.cndba.cn/Expect-le/article/2103

2.2   创建测试数据

-- 创建第一个表空间,表,并插入数据

http://www.cndba.cn/Expect-le/article/2103

CREATE TABLESPACE ts1
  DATAFILE '/u01/app/oracle/oradata/orcl/lei1/ts101.dbf'
  SIZE 1M AUTOEXTEND ON NEXT 1M;

CREATE USER test1 IDENTIFIED BY test1
  DEFAULT TABLESPACE ts1
  QUOTA UNLIMITED ON ts1;

CREATE TABLE test1.t1 (
  id NUMBER
);

INSERT INTO test1.t1 VALUES (1);
COMMIT;

-- 创建第二个表空间,表,并插入数据

CREATE TABLESPACE ts2
  DATAFILE '/u01/app/oracle/oradata/orcl/lei1/ts201.dbf'
  SIZE 1M AUTOEXTEND ON NEXT 1M;

CREATE USER test2 IDENTIFIED BY test2
  DEFAULT TABLESPACE ts2
  QUOTA UNLIMITED ON ts2;

CREATE TABLE test2.t2 (
  id NUMBER
);

INSERT INTO test2.t2 VALUES (1);
COMMIT;

http://www.cndba.cn/Expect-le/article/2103

-- 创建第三个表空间,表,并插入数据

CREATE TABLESPACE ts3
  DATAFILE '/u01/app/oracle/oradata/orcl/lei1/ts301.dbf'
  SIZE 1M AUTOEXTEND ON NEXT 1M;

CREATE USER test3 IDENTIFIED BY test3
  DEFAULT TABLESPACE ts3
  QUOTA UNLIMITED ON ts3;

CREATE TABLE test3.t3 (
  id NUMBER
);

INSERT INTO test3.t3 VALUES (1);
COMMIT;

2.3   查看创建的表空间

COLUMN owner FORMAT A20
COLUMN table_name FORMAT A20
COLUMN tablespace_name FORMAT A20
SELECT owner, table_name, tablespace_name
FROM   dba_tables
WHERE  table_name IN ('T1','T2','T3')
ORDER BY owner;
OWNER	     TABLE_NAME   TABLESPACE_NAME
-------------------- -------------------- --------------------
TEST1	     T1   TS1
TEST2	     T2   TS2
TEST3	     T3   TS3

http://www.cndba.cn/Expect-le/article/2103

2.4   LEI1克隆pdb3

CREATE PLUGGABLE DATABASE pdb3 FROM lei1
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/orcl/lei1/','/u01/app/oracle/oradata/orcl/pdb3/')
USER_TABLESPACES=('ts1', 'ts2');
Pluggable database created.

2.4.1  查看表空间

SQL> alter pluggable database pdb3 open;
Pluggable database altered.

SQL> alter session set container=pdb3;
Session altered.

SQL> SELECT tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
TS1
TS2
TS3
10 rows selected.

http://www.cndba.cn/Expect-le/article/2103

2.4.2  访问表空间中表的数据

SQL> SELECT * FROM test1.t1;
ID
----------
 1

SQL> SELECT * FROM test2.t2;
ID
----------
 1

SQL> SELECT * FROM test3.t3;
SELECT * FROM test3.t3
                    *
ERROR at line 1:
ORA-00376: file 63 cannot be read at this time
ORA-01110: data file 63: 'No file with this number, file does not exist'

可以看到tbs3表空间中表无法访问。就是没有被克隆过来。

--那么就可以删除tbs3

DROP TABLESPACE ts3 INCLUDING CONTENTS AND DATAFILES;

DROP USER test3 CASCADE;

同样支持下面的几个语法:

--所有用户创建的表空间都不克隆

USER_TABLESPACES=NONE;

--所有表空间都克隆

USER_TABLESPACES=ALL;

--除了ts3之外,其他表空间都克隆

http://www.cndba.cn/Expect-le/article/2103

USER_TABLESPACES=ALL EXCEPT('ts3');

官方文档:http://docs.oracle.com/database/121/ADMIN/cdb_plug.htm#ADMIN14241

http://www.cndba.cn/Expect-le/article/2103

版权声明:本文为博主原创文章,未经博主允许不得转载。

PDB Subset Cloning

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1553028次
  • 积分:1957
  • 等级:核心会员
  • 排名:第4名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ