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 | 设置子容器和数据文件副本的位置 |
-- 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';
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;
在12.1版本中在创建PDB时,SOURCE PDB必须处于read only状态,在12.2版本中,因为undo local mode新特性的推出,在创建PDB时,SOURCE PDB在read write状态也可以创建。而且,在12.2版本中Oracle推出了refresh PDB特性,具有对SOURCE PDB进行增量同步的功能。
CREATE PLUGGABLE DATABASE newpdb FROM salespdb
FILE_NAME_CONVERT = ('/disk1/oracle/dbs/salespdb/', '/disk1/oracle/dbs/newpdb/')
PATH_PREFIX = '/disk1/oracle/dbs/newpdb';
COL PROPERTY_NAME FOR A24
COL PROPERTY_VALUE FOR A16
SELECT property_name, property_value
FROM database_properties
WHERE property_name='LOCAL_UNDO_ENABLED';
create pluggable database pdb3 from pdb2 file_name_convert=('pdb2','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;
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;
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;
cd $ORACLE_HOME/network/admin
cat> tnsnames.ora <
create database link dblink1 connect to sys identified by oracle using 'orcl';
使用的用户必须拥有 CREATE PLUGGABLE DATABASE 的权限
select sysdate from dual@dblink1;
-- 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');
alter session set container=pdb4;
show pdbs
@?/rdbms/admin/noncdb_to_pdb.sql
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;
alter pluggable database pdb1 close immediate instances=all;
alter pluggable database pdb1 unplug into '/tmp/pdb1.xml';
drop pluggable database pdb1 keep datafiles;
keep datafiles:保留数据文件,不删除数据文件
使用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;
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.
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;