zoukankan      html  css  js  c++  java
  • Oracle-创建PDB

    创建PDB的方式

    • 从PDB$SEED新建PDB
    • 克隆已存在的PDB
      • 本地PDB克隆到同一个CDB中
      • 将远程PDB克隆到CDB中
    • 将非CDB插入或克隆到CDB中
    • 通过插拔的方式创建PDB

    image-20210909100643634

    sql 命令语法

    条件

    • CDB必须open并且read write模式
    • 连接CDB$ROOT 用户并且具有CREATE PLUGGABLE DATABASE系统权限

    具体实现

    从PDB$SEED新建PDB

    img

    示例

    CREATE PLUGGABLE DATABASE salespdb
      ADMIN USER salesadm IDENTIFIED BY password
      ROLES = (dba)
      DEFAULT TABLESPACE sales
        DATAFILE '/disk1/oracle/dbs/salespdb/sales01.dbf' SIZE 250M AUTOEXTEND ON
      FILE_NAME_CONVERT = ('/disk1/oracle/dbs/pdbseed/',
                           '/disk1/oracle/dbs/salespdb/')
      STORAGE (MAXSIZE 2G)
      PATH_PREFIX = '/disk1/oracle/dbs/salespdb/';
    
    参数说明
    关键字 描述
    ADMIN USER 用于执行管理任务的本地用户
    STORAGE (MAXSIZE 2G) 指定了PDB可用的最大空间
    DEFAULT TABLESPACE 为PDB指定默认的Tablespace
    PATH_PREFIX 用来限制directory objects/Oracle XML/Create pfile/Oracle wallets所在的目录
    FILE_NAME_CONVERT 设置子容器和数据文件副本的位置

    create pluggable database命令创建PDB2

    -- 12.1
    create pluggable database pdb2 admin user pdb2_admin identified by oracle roles=(connect) file_name_convert=('/u01/app/oracle/oradata/CDB3/pdbseed','/u01/app/oracle/oradata/CDB3/pdb2');
    
    -- 12.2
    create pluggable database pdb2 admin user pdbadmin identified by "oracle" create_file_dest='+DATA';
    
    

    打开PDB2

    alter pluggable database pdb2 open instances=all;
    alter pluggable database pdb2 save state instances=all;
    show pdbs;
    
    set lines 168 pages 99
    col name for a16
    col open_mode for a16
    col restricted for a12
    select inst_id, con_id, name, open_mode, restricted from gv$containers;
    

    克隆已存在的PDB

    克隆本地PDB

    img

    在12.1版本中在创建PDB时,SOURCE PDB必须处于read only状态,在12.2版本中,因为undo local mode新特性的推出,在创建PDB时,SOURCE PDB在read write状态也可以创建。而且,在12.2版本中Oracle推出了refresh PDB特性,具有对SOURCE PDB进行增量同步的功能。

    注意事项
    • 如果CDB为shared undo,PDB必须为READ-ONLY状态
    • 如果CDB不是归档模式,那么PDB必须为READ-ONLY状态
    • 如果是Oracle Database 版本为12.1,那么PDB只能为READ-ONLY状态,因在12.1中undo模式,还只能选择shared undo
    • 使用的用户必须拥有 CREATE PLUGGABLE DATABASE 的权限
    示例
    CREATE PLUGGABLE DATABASE newpdb FROM salespdb
      FILE_NAME_CONVERT = ('/disk1/oracle/dbs/salespdb/', '/disk1/oracle/dbs/newpdb/')
      PATH_PREFIX = '/disk1/oracle/dbs/newpdb';
    
    检查undo模式
    COL PROPERTY_NAME FOR A24
    COL PROPERTY_VALUE FOR A16
    SELECT property_name, property_value
    FROM database_properties
    WHERE property_name='LOCAL_UNDO_ENABLED';
    

    image-20210909102708748

    克隆方式创建PDB
    create pluggable database pdb3 from pdb2 file_name_convert=('pdb2','pdb3');
    
    打开PDB3
    alter pluggable database pdb3 open instances=all;
    alter pluggable database pdb3 save state instances=all;
    show pdbs;
    
    set lines 168 pages 99
    col name for a16
    col open_mode for a16
    col restricted for a12
    select inst_id, con_id, name, open_mode, restricted from gv$containers;
    

    克隆远程PDB或non-CDB

    img

    注意事项

    • 如果PDB被Clone到的CDB的字符集不是AL32UTF8,那么源与目标字符集必须兼容。
    • 源端与目标端的字节顺序必须相同.
    • 连接的用户在CDB中必须拥有'CREATE PLUGGABLE DATABASE'的权限
    • 源PDB不可以是关闭状态
    • 如果远端CDB为shared undo,源PDB必须为READ-ONLY状态
    • 如果远端CDB不是归档模式,源PDB必须为READ-ONLY状态

    准备

    查看源端与目标的字符集
    col parameter for a30
    col value for a30
    select * from nls_database_parameters where parameter='NLS_CHARACTERSET'
    or parameter='NLS_LANGUAGE' or parameter='NLS_NCHAR_CHARACTERSET';
    
    检查字节序
    col platform_name for a32
    SELECT d.inst_id, t.platform_id, t.platform_name, t.endian_format, d.name FROM v$transportable_platform t, gv$database d
    WHERE t.platform_name = d.platform_name;
    
    检查undo模式
    COL PROPERTY_NAME FOR A24
    COL PROPERTY_VALUE FOR A16
    SELECT property_name, property_value
    FROM database_properties
    WHERE property_name='LOCAL_UNDO_ENABLED';
    

    源库启动只读模式

    startup open read only;
    select open_mode from v$database;
    

    目标CDB中配置

    配置tnsnames.ora文件
    cd $ORACLE_HOME/network/admin
    cat> tnsnames.ora <<EOF
    ORCL =
        (DESCRIPTION =
            (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.181)(PORT = 1533))
            (LOAD_BALANCE = YES)
            (FAILOVER = ON)
            (CONNECT_DATA =
                (SERVER= DEDICATED)
                (SERVICE_NAME = ORCL)
                (FAILOVER_MODE =
                    (TYPE = select)
                    (METHOD = basic)
                    (RETRIES = 180)
                    (DELAY = 5)
                )
            )
        )
    EOF
    
    create database link dblink1 connect to sys identified by oracle using 'orcl';
    

    使用的用户必须拥有 CREATE PLUGGABLE DATABASE 的权限

    验证dblink连接
    select sysdate from dual@dblink1;
    
    克隆方式创建PDB
    -- non-CDB
    create pluggable database pdb4 from non$cdb@dblink1 file_name_convert=('/u01/app/oracle/oradata/ORCL','/u01/app/oracle/oradata/CDB3/pdb4');
    
    -- remote pdb
    create pluggable database pdb4 from pdb1@dblink1 file_name_convert=('/u01/app/oracle/oradata/ORCL','/u01/app/oracle/oradata/CDB3/pdb4');
    
    non-CDB转换pdb(可选)
    alter session set container=pdb4;
    show pdbs
    @?/rdbms/admin/noncdb_to_pdb.sql
    
    打开PDB
    alter pluggable database pdb4 open instances=all;
    alter pluggable database pdb4 save state instances=all;
    show pdbs;
    
    set lines 168 pages 99
    col name for a16
    col open_mode for a16
    col restricted for a12
    select inst_id, con_id, name, open_mode, restricted from gv$containers;
    

    拔插PDB

    拔出PDB

    img

    关闭PDB
    alter pluggable database pdb1 close immediate instances=all;
    
    拔出PDB
    alter pluggable database pdb1 unplug into '/tmp/pdb1.xml';
    
    删除PDB
    drop pluggable database pdb1 keep datafiles;
    

    keep datafiles:保留数据文件,不删除数据文件

    将拔插的PDB插入CDB

    img

    检查兼容性

    使用DBMS_PDB.CHECK_PLUG_COMPATIBILITY函数检查拔出的pdb1与cdb1是否兼容

    SET SERVEROUTPUT ON
    DECLARE
      compatible CONSTANT VARCHAR2(3) :=
        CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
          pdb_descr_file => '/tmp/pdb1.xml',
          pdb_name => 'PDB1')
        WHEN TRUE THEN 'YES'
        ELSE 'NO'
    END;
    BEGIN
      DBMS_OUTPUT.PUT_LINE(compatible);
    END;
    /
    
    示例
    CREATE PLUGGABLE DATABASE salespdb
      USING '/disk1/usr/salespdb.xml'
      SOURCE_FILE_NAME_CONVERT =
        ('/disk1/oracle/dbs/salespdb/', '/disk2/oracle/dbs/salespdb/')
      NOCOPY
      STORAGE (MAXSIZE 2G)
      TEMPFILE REUSE;
    
    插入CDB1
    create pluggable database pdb1 using '/tmp/pdb1.xml' nocopy;
    
    • COPY - Copy the tablespace files to the new location.
    • MOVE - Move the tablespace files to the new location.
    • NOCOPY - Do not copy or move the tablespace files to the new location.
    打开PDB
    alter pluggable database pdb1 open instances=all;
    alter pluggable database pdb1 save state instances=all;
    show pdbs;
    
    set lines 168 pages 99
    col name for a16
    col open_mode for a16
    col restricted for a12
    select inst_id, con_id, name, open_mode, restricted from gv$containers;
    
  • 相关阅读:
    bzoj 1016 JSOI2008 最小生成树计数
    bzoj 1070 SCOI2007 修车
    bzoj 1042 HAOI2008 硬币购物
    bzoj 1132 POI2008 Tro
    bzoj 1227 SDOI2009 虔诚的墓主人
    bzoj 1024 SCOI2009 生日快乐
    1103 POI2007 大都市meg
    bzoj 1009:[HNOI2008]GT考试
    noip2006T1 能量项链
    bzoj 1006: [HNOI2008]神奇的国度
  • 原文地址:https://www.cnblogs.com/binliubiao/p/15246126.html
Copyright © 2011-2022 走看看